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 * this code is based on the original GtkSignal implementation
20 * for the Gtk+ library by Peter Mattis <petm@xcf.berkeley.edu>
33 #include "gtype-private.h"
34 #include "gbsearcharray.h"
35 #include "gvaluecollector.h"
36 #include "gvaluetypes.h"
39 #include "gobject_trace.h"
44 * @short_description: A means for customization of object behaviour
45 * and a general purpose notification mechanism
48 * The basic concept of the signal system is that of the
49 * <emphasis>emission</emphasis> of a signal. Signals are introduced
50 * per-type and are identified through strings. Signals introduced
51 * for a parent type are available in derived types as well, so
52 * basically they are a per-type facility that is inherited. A signal
53 * emission mainly involves invocation of a certain set of callbacks
54 * in precisely defined manner. There are two main categories of such
55 * callbacks, per-object
56 * <footnote><para>Although signals can deal with any kind of instantiatable
57 * type, i'm referring to those types as "object types" in the following,
58 * simply because that is the context most users will encounter signals in.
60 * ones and user provided ones.
61 * The per-object callbacks are most often referred to as "object method
62 * handler" or "default (signal) handler", while user provided callbacks are
63 * usually just called "signal handler".
64 * The object method handler is provided at signal creation time (this most
65 * frequently happens at the end of an object class' creation), while user
66 * provided handlers are frequently connected and disconnected to/from a certain
67 * signal on certain object instances.
69 * A signal emission consists of five stages, unless prematurely stopped:
71 * <varlistentry><term></term><listitem><para>
72 * 1 - Invocation of the object method handler for %G_SIGNAL_RUN_FIRST signals
73 * </para></listitem></varlistentry>
74 * <varlistentry><term></term><listitem><para>
75 * 2 - Invocation of normal user-provided signal handlers (<emphasis>after</emphasis> flag %FALSE)
76 * </para></listitem></varlistentry>
77 * <varlistentry><term></term><listitem><para>
78 * 3 - Invocation of the object method handler for %G_SIGNAL_RUN_LAST signals
79 * </para></listitem></varlistentry>
80 * <varlistentry><term></term><listitem><para>
81 * 4 - Invocation of user provided signal handlers, connected with an <emphasis>after</emphasis> flag of %TRUE
82 * </para></listitem></varlistentry>
83 * <varlistentry><term></term><listitem><para>
84 * 5 - Invocation of the object method handler for %G_SIGNAL_RUN_CLEANUP signals
85 * </para></listitem></varlistentry>
87 * The user-provided signal handlers are called in the order they were
89 * All handlers may prematurely stop a signal emission, and any number of
90 * handlers may be connected, disconnected, blocked or unblocked during
92 * There are certain criteria for skipping user handlers in stages 2 and 4
93 * of a signal emission.
94 * First, user handlers may be <emphasis>blocked</emphasis>, blocked handlers are omitted
95 * during callback invocation, to return from the "blocked" state, a
96 * handler has to get unblocked exactly the same amount of times
97 * it has been blocked before.
98 * Second, upon emission of a %G_SIGNAL_DETAILED signal, an additional
99 * "detail" argument passed in to g_signal_emit() has to match the detail
100 * argument of the signal handler currently subject to invocation.
101 * Specification of no detail argument for signal handlers (omission of the
102 * detail part of the signal specification upon connection) serves as a
103 * wildcard and matches any detail argument passed in to emission.
107 #define REPORT_BUG "please report occurrence circumstances to gtk-devel-list@gnome.org"
108 #ifdef G_ENABLE_DEBUG
109 #define IF_DEBUG(debug_type, cond) if ((_g_type_debug_flags & G_TYPE_DEBUG_ ## debug_type) || cond)
110 static volatile gpointer g_trace_instance_signals = NULL;
111 static volatile gpointer g_trap_instance_signals = NULL;
112 #endif /* G_ENABLE_DEBUG */
115 /* --- typedefs --- */
116 typedef struct _SignalNode SignalNode;
117 typedef struct _SignalKey SignalKey;
118 typedef struct _Emission Emission;
119 typedef struct _Handler Handler;
120 typedef struct _HandlerList HandlerList;
121 typedef struct _HandlerMatch HandlerMatch;
131 /* --- prototypes --- */
132 static inline guint signal_id_lookup (GQuark quark,
134 static void signal_destroy_R (SignalNode *signal_node);
135 static inline HandlerList* handler_list_ensure (guint signal_id,
137 static inline HandlerList* handler_list_lookup (guint signal_id,
139 static inline Handler* handler_new (gboolean after);
140 static void handler_insert (guint signal_id,
143 static Handler* handler_lookup (gpointer instance,
146 static inline HandlerMatch* handler_match_prepend (HandlerMatch *list,
149 static inline HandlerMatch* handler_match_free1_R (HandlerMatch *node,
151 static HandlerMatch* handlers_find (gpointer instance,
152 GSignalMatchType mask,
158 gboolean one_and_only);
159 static inline void handler_ref (Handler *handler);
160 static inline void handler_unref_R (guint signal_id,
163 static gint handler_lists_cmp (gconstpointer node1,
164 gconstpointer node2);
165 static inline void emission_push (Emission **emission_list_p,
167 static inline void emission_pop (Emission **emission_list_p,
169 static inline Emission* emission_find (Emission *emission_list,
173 static gint class_closures_cmp (gconstpointer node1,
174 gconstpointer node2);
175 static gint signal_key_cmp (gconstpointer node1,
176 gconstpointer node2);
177 static gboolean signal_emit_unlocked_R (SignalNode *node,
180 GValue *return_value,
181 const GValue *instance_and_params);
182 static const gchar * type_debug_name (GType type);
185 /* --- structures --- */
188 GSignalAccumulator func;
196 #define SIGNAL_HOOK(hook) ((SignalHook*) (hook))
200 /* permanent portion */
206 /* reinitializable portion */
207 guint test_class_offset : 12;
210 GType *param_types; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
211 GType return_type; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
212 GBSearchArray *class_closure_bsa;
213 SignalAccumulator *accumulator;
214 GSignalCMarshaller c_marshaller;
215 GHookList *emission_hooks;
217 #define MAX_TEST_CLASS_OFFSET (4096) /* 2^12, 12 bits for test_class_offset */
218 #define TEST_CLASS_MAGIC (1) /* indicates NULL class closure, candidate for NOP optimization */
231 GSignalInvocationHint ihint;
240 Handler *tail_before; /* normal signal handlers are appended here */
241 Handler *tail_after; /* CONNECT_AFTER handlers are appended here */
246 gulong sequential_number;
251 guint block_count : 16;
252 #define HANDLER_MAX_BLOCK_COUNT (1 << 16)
265 GType instance_type; /* 0 for default closure */
270 /* --- variables --- */
271 static GBSearchArray *g_signal_key_bsa = NULL;
272 static const GBSearchConfig g_signal_key_bconfig = {
275 G_BSEARCH_ARRAY_ALIGN_POWER2,
277 static GBSearchConfig g_signal_hlbsa_bconfig = {
278 sizeof (HandlerList),
282 static GBSearchConfig g_class_closure_bconfig = {
283 sizeof (ClassClosure),
287 static GHashTable *g_handler_list_bsa_ht = NULL;
288 static Emission *g_recursive_emissions = NULL;
289 static Emission *g_restart_emissions = NULL;
290 static gulong g_handler_sequential_number = 1;
291 G_LOCK_DEFINE_STATIC (g_signal_mutex);
292 #define SIGNAL_LOCK() G_LOCK (g_signal_mutex)
293 #define SIGNAL_UNLOCK() G_UNLOCK (g_signal_mutex)
296 /* --- signal nodes --- */
297 static guint g_n_signal_nodes = 0;
298 static SignalNode **g_signal_nodes = NULL;
300 static inline SignalNode*
301 LOOKUP_SIGNAL_NODE (register guint signal_id)
303 if (signal_id < g_n_signal_nodes)
304 return g_signal_nodes[signal_id];
310 /* --- functions --- */
312 signal_id_lookup (GQuark quark,
315 GType *ifaces, type = itype;
321 /* try looking up signals for this type and its ancestors */
324 SignalKey *signal_key;
327 signal_key = g_bsearch_array_lookup (g_signal_key_bsa, &g_signal_key_bconfig, &key);
330 return signal_key->signal_id;
332 type = g_type_parent (type);
336 /* no luck, try interfaces it exports */
337 ifaces = g_type_interfaces (itype, &n_ifaces);
340 SignalKey *signal_key;
342 key.itype = ifaces[n_ifaces];
343 signal_key = g_bsearch_array_lookup (g_signal_key_bsa, &g_signal_key_bconfig, &key);
348 return signal_key->signal_id;
357 class_closures_cmp (gconstpointer node1,
360 const ClassClosure *c1 = node1, *c2 = node2;
362 return G_BSEARCH_ARRAY_CMP (c1->instance_type, c2->instance_type);
366 handler_lists_cmp (gconstpointer node1,
369 const HandlerList *hlist1 = node1, *hlist2 = node2;
371 return G_BSEARCH_ARRAY_CMP (hlist1->signal_id, hlist2->signal_id);
374 static inline HandlerList*
375 handler_list_ensure (guint signal_id,
378 GBSearchArray *hlbsa = g_hash_table_lookup (g_handler_list_bsa_ht, instance);
381 key.signal_id = signal_id;
383 key.tail_before = NULL;
384 key.tail_after = NULL;
387 hlbsa = g_bsearch_array_create (&g_signal_hlbsa_bconfig);
388 hlbsa = g_bsearch_array_insert (hlbsa, &g_signal_hlbsa_bconfig, &key);
389 g_hash_table_insert (g_handler_list_bsa_ht, instance, hlbsa);
393 GBSearchArray *o = hlbsa;
395 hlbsa = g_bsearch_array_insert (o, &g_signal_hlbsa_bconfig, &key);
397 g_hash_table_insert (g_handler_list_bsa_ht, instance, hlbsa);
399 return g_bsearch_array_lookup (hlbsa, &g_signal_hlbsa_bconfig, &key);
402 static inline HandlerList*
403 handler_list_lookup (guint signal_id,
406 GBSearchArray *hlbsa = g_hash_table_lookup (g_handler_list_bsa_ht, instance);
409 key.signal_id = signal_id;
411 return hlbsa ? g_bsearch_array_lookup (hlbsa, &g_signal_hlbsa_bconfig, &key) : NULL;
415 handler_lookup (gpointer instance,
419 GBSearchArray *hlbsa = g_hash_table_lookup (g_handler_list_bsa_ht, instance);
425 for (i = 0; i < hlbsa->n_nodes; i++)
427 HandlerList *hlist = g_bsearch_array_get_nth (hlbsa, &g_signal_hlbsa_bconfig, i);
430 for (handler = hlist->handlers; handler; handler = handler->next)
431 if (handler->sequential_number == handler_id)
434 *signal_id_p = hlist->signal_id;
444 static inline HandlerMatch*
445 handler_match_prepend (HandlerMatch *list,
451 node = g_slice_new (HandlerMatch);
452 node->handler = handler;
454 node->signal_id = signal_id;
455 handler_ref (handler);
459 static inline HandlerMatch*
460 handler_match_free1_R (HandlerMatch *node,
463 HandlerMatch *next = node->next;
465 handler_unref_R (node->signal_id, instance, node->handler);
466 g_slice_free (HandlerMatch, node);
472 handlers_find (gpointer instance,
473 GSignalMatchType mask,
479 gboolean one_and_only)
481 HandlerMatch *mlist = NULL;
483 if (mask & G_SIGNAL_MATCH_ID)
485 HandlerList *hlist = handler_list_lookup (signal_id, instance);
487 SignalNode *node = NULL;
489 if (mask & G_SIGNAL_MATCH_FUNC)
491 node = LOOKUP_SIGNAL_NODE (signal_id);
492 if (!node || !node->c_marshaller)
497 for (handler = hlist ? hlist->handlers : NULL; handler; handler = handler->next)
498 if (handler->sequential_number &&
499 ((mask & G_SIGNAL_MATCH_DETAIL) || handler->detail == detail) &&
500 ((mask & G_SIGNAL_MATCH_CLOSURE) || handler->closure == closure) &&
501 ((mask & G_SIGNAL_MATCH_DATA) || handler->closure->data == data) &&
502 ((mask & G_SIGNAL_MATCH_UNBLOCKED) || handler->block_count == 0) &&
503 ((mask & G_SIGNAL_MATCH_FUNC) || (handler->closure->marshal == node->c_marshaller &&
504 handler->closure->meta_marshal == 0 &&
505 ((GCClosure*) handler->closure)->callback == func)))
507 mlist = handler_match_prepend (mlist, handler, signal_id);
514 GBSearchArray *hlbsa = g_hash_table_lookup (g_handler_list_bsa_ht, instance);
521 for (i = 0; i < hlbsa->n_nodes; i++)
523 HandlerList *hlist = g_bsearch_array_get_nth (hlbsa, &g_signal_hlbsa_bconfig, i);
524 SignalNode *node = NULL;
527 if (!(mask & G_SIGNAL_MATCH_FUNC))
529 node = LOOKUP_SIGNAL_NODE (hlist->signal_id);
530 if (!node->c_marshaller)
534 for (handler = hlist->handlers; handler; handler = handler->next)
535 if (handler->sequential_number &&
536 ((mask & G_SIGNAL_MATCH_DETAIL) || handler->detail == detail) &&
537 ((mask & G_SIGNAL_MATCH_CLOSURE) || handler->closure == closure) &&
538 ((mask & G_SIGNAL_MATCH_DATA) || handler->closure->data == data) &&
539 ((mask & G_SIGNAL_MATCH_UNBLOCKED) || handler->block_count == 0) &&
540 ((mask & G_SIGNAL_MATCH_FUNC) || (handler->closure->marshal == node->c_marshaller &&
541 handler->closure->meta_marshal == 0 &&
542 ((GCClosure*) handler->closure)->callback == func)))
544 mlist = handler_match_prepend (mlist, handler, hlist->signal_id);
555 static inline Handler*
556 handler_new (gboolean after)
558 Handler *handler = g_slice_new (Handler);
559 #ifndef G_DISABLE_CHECKS
560 if (g_handler_sequential_number < 1)
561 g_error (G_STRLOC ": handler id overflow, %s", REPORT_BUG);
564 handler->sequential_number = g_handler_sequential_number++;
565 handler->prev = NULL;
566 handler->next = NULL;
568 handler->ref_count = 1;
569 handler->block_count = 0;
570 handler->after = after != FALSE;
571 handler->closure = NULL;
577 handler_ref (Handler *handler)
579 g_return_if_fail (handler->ref_count > 0);
581 g_atomic_int_inc ((int *)&handler->ref_count);
585 handler_unref_R (guint signal_id,
591 g_return_if_fail (handler->ref_count > 0);
593 is_zero = g_atomic_int_dec_and_test ((int *)&handler->ref_count);
595 if (G_UNLIKELY (is_zero))
597 HandlerList *hlist = NULL;
600 handler->next->prev = handler->prev;
601 if (handler->prev) /* watch out for g_signal_handlers_destroy()! */
602 handler->prev->next = handler->next;
605 hlist = handler_list_lookup (signal_id, instance);
606 hlist->handlers = handler->next;
611 /* check if we are removing the handler pointed to by tail_before */
612 if (!handler->after && (!handler->next || handler->next->after))
615 hlist = handler_list_lookup (signal_id, instance);
618 g_assert (hlist->tail_before == handler); /* paranoid */
619 hlist->tail_before = handler->prev;
623 /* check if we are removing the handler pointed to by tail_after */
627 hlist = handler_list_lookup (signal_id, instance);
630 g_assert (hlist->tail_after == handler); /* paranoid */
631 hlist->tail_after = handler->prev;
637 g_closure_unref (handler->closure);
639 g_slice_free (Handler, handler);
644 handler_insert (guint signal_id,
650 g_assert (handler->prev == NULL && handler->next == NULL); /* paranoid */
652 hlist = handler_list_ensure (signal_id, instance);
653 if (!hlist->handlers)
655 hlist->handlers = handler;
657 hlist->tail_before = handler;
659 else if (handler->after)
661 handler->prev = hlist->tail_after;
662 hlist->tail_after->next = handler;
666 if (hlist->tail_before)
668 handler->next = hlist->tail_before->next;
670 handler->next->prev = handler;
671 handler->prev = hlist->tail_before;
672 hlist->tail_before->next = handler;
674 else /* insert !after handler into a list of only after handlers */
676 handler->next = hlist->handlers;
678 handler->next->prev = handler;
679 hlist->handlers = handler;
681 hlist->tail_before = handler;
685 hlist->tail_after = handler;
689 emission_push (Emission **emission_list_p,
692 emission->next = *emission_list_p;
693 *emission_list_p = emission;
697 emission_pop (Emission **emission_list_p,
700 Emission *node, *last = NULL;
702 for (node = *emission_list_p; node; last = node, node = last->next)
703 if (node == emission)
706 last->next = node->next;
708 *emission_list_p = node->next;
711 g_assert_not_reached ();
714 static inline Emission*
715 emission_find (Emission *emission_list,
722 for (emission = emission_list; emission; emission = emission->next)
723 if (emission->instance == instance &&
724 emission->ihint.signal_id == signal_id &&
725 emission->ihint.detail == detail)
730 static inline Emission*
731 emission_find_innermost (gpointer instance)
733 Emission *emission, *s = NULL, *c = NULL;
735 for (emission = g_restart_emissions; emission; emission = emission->next)
736 if (emission->instance == instance)
741 for (emission = g_recursive_emissions; emission; emission = emission->next)
742 if (emission->instance == instance)
752 return G_HAVE_GROWING_STACK ? MAX (c, s) : MIN (c, s);
756 signal_key_cmp (gconstpointer node1,
759 const SignalKey *key1 = node1, *key2 = node2;
761 if (key1->itype == key2->itype)
762 return G_BSEARCH_ARRAY_CMP (key1->quark, key2->quark);
764 return G_BSEARCH_ARRAY_CMP (key1->itype, key2->itype);
768 _g_signal_init (void)
771 if (!g_n_signal_nodes)
773 /* setup handler list binary searchable array hash table (in german, that'd be one word ;) */
774 g_handler_list_bsa_ht = g_hash_table_new (g_direct_hash, NULL);
775 g_signal_key_bsa = g_bsearch_array_create (&g_signal_key_bconfig);
777 /* invalid (0) signal_id */
778 g_n_signal_nodes = 1;
779 g_signal_nodes = g_renew (SignalNode*, g_signal_nodes, g_n_signal_nodes);
780 g_signal_nodes[0] = NULL;
786 _g_signals_destroy (GType itype)
791 for (i = 1; i < g_n_signal_nodes; i++)
793 SignalNode *node = g_signal_nodes[i];
795 if (node->itype == itype)
798 g_warning (G_STRLOC ": signal \"%s\" of type `%s' already destroyed",
800 type_debug_name (node->itype));
802 signal_destroy_R (node);
809 * g_signal_stop_emission:
810 * @instance: the object whose signal handlers you wish to stop.
811 * @signal_id: the signal identifier, as returned by g_signal_lookup().
812 * @detail: the detail which the signal was emitted with.
814 * Stops a signal's current emission.
816 * This will prevent the default method from running, if the signal was
817 * %G_SIGNAL_RUN_LAST and you connected normally (i.e. without the "after"
820 * Prints a warning if used on a signal which isn't being emitted.
823 g_signal_stop_emission (gpointer instance,
829 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
830 g_return_if_fail (signal_id > 0);
833 node = LOOKUP_SIGNAL_NODE (signal_id);
834 if (node && detail && !(node->flags & G_SIGNAL_DETAILED))
836 g_warning ("%s: signal id `%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
840 if (node && g_type_is_a (G_TYPE_FROM_INSTANCE (instance), node->itype))
842 Emission *emission_list = node->flags & G_SIGNAL_NO_RECURSE ? g_restart_emissions : g_recursive_emissions;
843 Emission *emission = emission_find (emission_list, signal_id, detail, instance);
847 if (emission->state == EMISSION_HOOK)
848 g_warning (G_STRLOC ": emission of signal \"%s\" for instance `%p' cannot be stopped from emission hook",
849 node->name, instance);
850 else if (emission->state == EMISSION_RUN)
851 emission->state = EMISSION_STOP;
854 g_warning (G_STRLOC ": no emission of signal \"%s\" to stop for instance `%p'",
855 node->name, instance);
858 g_warning ("%s: signal id `%u' is invalid for instance `%p'", G_STRLOC, signal_id, instance);
863 signal_finalize_hook (GHookList *hook_list,
866 GDestroyNotify destroy = hook->destroy;
870 hook->destroy = NULL;
872 destroy (hook->data);
878 * g_signal_add_emission_hook:
879 * @signal_id: the signal identifier, as returned by g_signal_lookup().
880 * @detail: the detail on which to call the hook.
881 * @hook_func: a #GSignalEmissionHook function.
882 * @hook_data: user data for @hook_func.
883 * @data_destroy: a #GDestroyNotify for @hook_data.
885 * Adds an emission hook for a signal, which will get called for any emission
886 * of that signal, independent of the instance. This is possible only
887 * for signals which don't have #G_SIGNAL_NO_HOOKS flag set.
889 * Returns: the hook id, for later use with g_signal_remove_emission_hook().
892 g_signal_add_emission_hook (guint signal_id,
894 GSignalEmissionHook hook_func,
896 GDestroyNotify data_destroy)
898 static gulong seq_hook_id = 1;
901 SignalHook *signal_hook;
903 g_return_val_if_fail (signal_id > 0, 0);
904 g_return_val_if_fail (hook_func != NULL, 0);
907 node = LOOKUP_SIGNAL_NODE (signal_id);
908 if (!node || node->destroyed)
910 g_warning ("%s: invalid signal id `%u'", G_STRLOC, signal_id);
914 if (node->flags & G_SIGNAL_NO_HOOKS)
916 g_warning ("%s: signal id `%u' does not support emission hooks (G_SIGNAL_NO_HOOKS flag set)", G_STRLOC, signal_id);
920 if (detail && !(node->flags & G_SIGNAL_DETAILED))
922 g_warning ("%s: signal id `%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
926 if (!node->emission_hooks)
928 node->emission_hooks = g_new (GHookList, 1);
929 g_hook_list_init (node->emission_hooks, sizeof (SignalHook));
930 node->emission_hooks->finalize_hook = signal_finalize_hook;
932 hook = g_hook_alloc (node->emission_hooks);
933 hook->data = hook_data;
934 hook->func = (gpointer) hook_func;
935 hook->destroy = data_destroy;
936 signal_hook = SIGNAL_HOOK (hook);
937 signal_hook->detail = detail;
938 node->emission_hooks->seq_id = seq_hook_id;
939 g_hook_append (node->emission_hooks, hook);
940 seq_hook_id = node->emission_hooks->seq_id;
943 return hook->hook_id;
947 * g_signal_remove_emission_hook:
948 * @signal_id: the id of the signal
949 * @hook_id: the id of the emission hook, as returned by
950 * g_signal_add_emission_hook()
952 * Deletes an emission hook.
955 g_signal_remove_emission_hook (guint signal_id,
960 g_return_if_fail (signal_id > 0);
961 g_return_if_fail (hook_id > 0);
964 node = LOOKUP_SIGNAL_NODE (signal_id);
965 if (!node || node->destroyed)
966 g_warning ("%s: invalid signal id `%u'", G_STRLOC, signal_id);
967 else if (!node->emission_hooks || !g_hook_destroy (node->emission_hooks, hook_id))
968 g_warning ("%s: signal \"%s\" had no hook (%lu) to remove", G_STRLOC, node->name, hook_id);
973 signal_parse_name (const gchar *name,
976 gboolean force_quark)
978 const gchar *colon = strchr (name, ':');
983 signal_id = signal_id_lookup (g_quark_try_string (name), itype);
984 if (signal_id && detail_p)
987 else if (colon[1] == ':')
990 guint l = colon - name;
994 memcpy (buffer, name, l);
996 signal_id = signal_id_lookup (g_quark_try_string (buffer), itype);
1000 gchar *signal = g_new (gchar, l + 1);
1002 memcpy (signal, name, l);
1004 signal_id = signal_id_lookup (g_quark_try_string (signal), itype);
1008 if (signal_id && detail_p)
1009 *detail_p = colon[2] ? (force_quark ? g_quark_from_string : g_quark_try_string) (colon + 2) : 0;
1017 * g_signal_parse_name:
1018 * @detailed_signal: a string of the form "signal-name::detail".
1019 * @itype: The interface/instance type that introduced "signal-name".
1020 * @signal_id_p: (out): Location to store the signal id.
1021 * @detail_p: (out): Location to store the detail quark.
1022 * @force_detail_quark: %TRUE forces creation of a #GQuark for the detail.
1024 * Internal function to parse a signal name into its @signal_id
1025 * and @detail quark.
1027 * Returns: Whether the signal name could successfully be parsed and @signal_id_p and @detail_p contain valid return values.
1030 g_signal_parse_name (const gchar *detailed_signal,
1034 gboolean force_detail_quark)
1040 g_return_val_if_fail (detailed_signal != NULL, FALSE);
1041 g_return_val_if_fail (G_TYPE_IS_INSTANTIATABLE (itype) || G_TYPE_IS_INTERFACE (itype), FALSE);
1044 signal_id = signal_parse_name (detailed_signal, itype, &detail, force_detail_quark);
1047 node = signal_id ? LOOKUP_SIGNAL_NODE (signal_id) : NULL;
1048 if (!node || node->destroyed ||
1049 (detail && !(node->flags & G_SIGNAL_DETAILED)))
1053 *signal_id_p = signal_id;
1061 * g_signal_stop_emission_by_name:
1062 * @instance: the object whose signal handlers you wish to stop.
1063 * @detailed_signal: a string of the form "signal-name::detail".
1065 * Stops a signal's current emission.
1067 * This is just like g_signal_stop_emission() except it will look up the
1068 * signal id for you.
1071 g_signal_stop_emission_by_name (gpointer instance,
1072 const gchar *detailed_signal)
1078 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
1079 g_return_if_fail (detailed_signal != NULL);
1082 itype = G_TYPE_FROM_INSTANCE (instance);
1083 signal_id = signal_parse_name (detailed_signal, itype, &detail, TRUE);
1086 SignalNode *node = LOOKUP_SIGNAL_NODE (signal_id);
1088 if (detail && !(node->flags & G_SIGNAL_DETAILED))
1089 g_warning ("%s: signal `%s' does not support details", G_STRLOC, detailed_signal);
1090 else if (!g_type_is_a (itype, node->itype))
1091 g_warning ("%s: signal `%s' is invalid for instance `%p'", G_STRLOC, detailed_signal, instance);
1094 Emission *emission_list = node->flags & G_SIGNAL_NO_RECURSE ? g_restart_emissions : g_recursive_emissions;
1095 Emission *emission = emission_find (emission_list, signal_id, detail, instance);
1099 if (emission->state == EMISSION_HOOK)
1100 g_warning (G_STRLOC ": emission of signal \"%s\" for instance `%p' cannot be stopped from emission hook",
1101 node->name, instance);
1102 else if (emission->state == EMISSION_RUN)
1103 emission->state = EMISSION_STOP;
1106 g_warning (G_STRLOC ": no emission of signal \"%s\" to stop for instance `%p'",
1107 node->name, instance);
1111 g_warning ("%s: signal `%s' is invalid for instance `%p'", G_STRLOC, detailed_signal, instance);
1117 * @name: the signal's name.
1118 * @itype: the type that the signal operates on.
1120 * Given the name of the signal and the type of object it connects to, gets
1121 * the signal's identifying integer. Emitting the signal by number is
1122 * somewhat faster than using the name each time.
1124 * Also tries the ancestors of the given type.
1126 * See g_signal_new() for details on allowed signal names.
1128 * Returns: the signal's identifying number, or 0 if no signal was found.
1131 g_signal_lookup (const gchar *name,
1135 g_return_val_if_fail (name != NULL, 0);
1136 g_return_val_if_fail (G_TYPE_IS_INSTANTIATABLE (itype) || G_TYPE_IS_INTERFACE (itype), 0);
1139 signal_id = signal_id_lookup (g_quark_try_string (name), itype);
1143 /* give elaborate warnings */
1144 if (!g_type_name (itype))
1145 g_warning (G_STRLOC ": unable to lookup signal \"%s\" for invalid type id `%"G_GSIZE_FORMAT"'",
1147 else if (!G_TYPE_IS_INSTANTIATABLE (itype))
1148 g_warning (G_STRLOC ": unable to lookup signal \"%s\" for non instantiatable type `%s'",
1149 name, g_type_name (itype));
1150 else if (!g_type_class_peek (itype))
1151 g_warning (G_STRLOC ": unable to lookup signal \"%s\" of unloaded type `%s'",
1152 name, g_type_name (itype));
1159 * g_signal_list_ids:
1160 * @itype: Instance or interface type.
1161 * @n_ids: Location to store the number of signal ids for @itype.
1163 * Lists the signals by id that a certain instance or interface type
1164 * created. Further information about the signals can be acquired through
1167 * Returns: (array length=n_ids): Newly allocated array of signal IDs.
1170 g_signal_list_ids (GType itype,
1178 g_return_val_if_fail (G_TYPE_IS_INSTANTIATABLE (itype) || G_TYPE_IS_INTERFACE (itype), NULL);
1179 g_return_val_if_fail (n_ids != NULL, NULL);
1182 keys = g_bsearch_array_get_nth (g_signal_key_bsa, &g_signal_key_bconfig, 0);
1183 n_nodes = g_bsearch_array_get_n_nodes (g_signal_key_bsa);
1184 result = g_array_new (FALSE, FALSE, sizeof (guint));
1186 for (i = 0; i < n_nodes; i++)
1187 if (keys[i].itype == itype)
1189 const gchar *name = g_quark_to_string (keys[i].quark);
1191 /* Signal names with "_" in them are aliases to the same
1192 * name with "-" instead of "_".
1194 if (!strchr (name, '_'))
1195 g_array_append_val (result, keys[i].signal_id);
1197 *n_ids = result->len;
1201 /* give elaborate warnings */
1202 if (!g_type_name (itype))
1203 g_warning (G_STRLOC ": unable to list signals for invalid type id `%"G_GSIZE_FORMAT"'",
1205 else if (!G_TYPE_IS_INSTANTIATABLE (itype) && !G_TYPE_IS_INTERFACE (itype))
1206 g_warning (G_STRLOC ": unable to list signals of non instantiatable type `%s'",
1207 g_type_name (itype));
1208 else if (!g_type_class_peek (itype) && !G_TYPE_IS_INTERFACE (itype))
1209 g_warning (G_STRLOC ": unable to list signals of unloaded type `%s'",
1210 g_type_name (itype));
1213 return (guint*) g_array_free (result, FALSE);
1218 * @signal_id: the signal's identifying number.
1220 * Given the signal's identifier, finds its name.
1222 * Two different signals may have the same name, if they have differing types.
1224 * Returns: the signal name, or %NULL if the signal number was invalid.
1227 g_signal_name (guint signal_id)
1233 node = LOOKUP_SIGNAL_NODE (signal_id);
1234 name = node ? node->name : NULL;
1237 return (char*) name;
1242 * @signal_id: The signal id of the signal to query information for.
1243 * @query: (out caller-allocates): A user provided structure that is
1244 * filled in with constant values upon success.
1246 * Queries the signal system for in-depth information about a
1247 * specific signal. This function will fill in a user-provided
1248 * structure to hold signal-specific information. If an invalid
1249 * signal id is passed in, the @signal_id member of the #GSignalQuery
1250 * is 0. All members filled into the #GSignalQuery structure should
1251 * be considered constant and have to be left untouched.
1254 g_signal_query (guint signal_id,
1255 GSignalQuery *query)
1259 g_return_if_fail (query != NULL);
1262 node = LOOKUP_SIGNAL_NODE (signal_id);
1263 if (!node || node->destroyed)
1264 query->signal_id = 0;
1267 query->signal_id = node->signal_id;
1268 query->signal_name = node->name;
1269 query->itype = node->itype;
1270 query->signal_flags = node->flags;
1271 query->return_type = node->return_type;
1272 query->n_params = node->n_params;
1273 query->param_types = node->param_types;
1280 * @signal_name: the name for the signal
1281 * @itype: the type this signal pertains to. It will also pertain to
1282 * types which are derived from this type.
1283 * @signal_flags: a combination of #GSignalFlags specifying detail of when
1284 * the default handler is to be invoked. You should at least specify
1285 * %G_SIGNAL_RUN_FIRST or %G_SIGNAL_RUN_LAST.
1286 * @class_offset: The offset of the function pointer in the class structure
1287 * for this type. Used to invoke a class method generically. Pass 0 to
1288 * not associate a class method slot with this signal.
1289 * @accumulator: the accumulator for this signal; may be %NULL.
1290 * @accu_data: user data for the @accumulator.
1291 * @c_marshaller: (allow-none): the function to translate arrays of parameter
1292 * values to signal emissions into C language callback invocations or %NULL.
1293 * @return_type: the type of return value, or #G_TYPE_NONE for a signal
1294 * without a return value.
1295 * @n_params: the number of parameter types to follow.
1296 * @...: a list of types, one for each parameter.
1298 * Creates a new signal. (This is usually done in the class initializer.)
1300 * A signal name consists of segments consisting of ASCII letters and
1301 * digits, separated by either the '-' or '_' character. The first
1302 * character of a signal name must be a letter. Names which violate these
1303 * rules lead to undefined behaviour of the GSignal system.
1305 * When registering a signal and looking up a signal, either separator can
1306 * be used, but they cannot be mixed.
1308 * If 0 is used for @class_offset subclasses cannot override the class handler
1309 * in their <code>class_init</code> method by doing
1310 * <code>super_class->signal_handler = my_signal_handler</code>. Instead they
1311 * will have to use g_signal_override_class_handler().
1313 * If c_marshaller is %NULL, g_cclosure_marshal_generic() will be used as
1314 * the marshaller for this signal.
1316 * Returns: the signal id
1319 g_signal_new (const gchar *signal_name,
1321 GSignalFlags signal_flags,
1323 GSignalAccumulator accumulator,
1325 GSignalCMarshaller c_marshaller,
1333 g_return_val_if_fail (signal_name != NULL, 0);
1335 va_start (args, n_params);
1337 signal_id = g_signal_new_valist (signal_name, itype, signal_flags,
1338 class_offset ? g_signal_type_cclosure_new (itype, class_offset) : NULL,
1339 accumulator, accu_data, c_marshaller,
1340 return_type, n_params, args);
1344 /* optimize NOP emissions with NULL class handlers */
1345 if (signal_id && G_TYPE_IS_INSTANTIATABLE (itype) && return_type == G_TYPE_NONE &&
1346 class_offset && class_offset < MAX_TEST_CLASS_OFFSET &&
1347 ~signal_flags & G_SIGNAL_MUST_COLLECT)
1352 node = LOOKUP_SIGNAL_NODE (signal_id);
1353 node->test_class_offset = class_offset;
1361 * g_signal_new_class_handler:
1362 * @signal_name: the name for the signal
1363 * @itype: the type this signal pertains to. It will also pertain to
1364 * types which are derived from this type.
1365 * @signal_flags: a combination of #GSignalFlags specifying detail of when
1366 * the default handler is to be invoked. You should at least specify
1367 * %G_SIGNAL_RUN_FIRST or %G_SIGNAL_RUN_LAST.
1368 * @class_handler: a #GCallback which acts as class implementation of
1369 * this signal. Used to invoke a class method generically. Pass %NULL to
1370 * not associate a class method with this signal.
1371 * @accumulator: the accumulator for this signal; may be %NULL.
1372 * @accu_data: user data for the @accumulator.
1373 * @c_marshaller: (allow-none): the function to translate arrays of parameter
1374 * values to signal emissions into C language callback invocations or %NULL.
1375 * @return_type: the type of return value, or #G_TYPE_NONE for a signal
1376 * without a return value.
1377 * @n_params: the number of parameter types to follow.
1378 * @...: a list of types, one for each parameter.
1380 * Creates a new signal. (This is usually done in the class initializer.)
1382 * This is a variant of g_signal_new() that takes a C callback instead
1383 * off a class offset for the signal's class handler. This function
1384 * doesn't need a function pointer exposed in the class structure of
1385 * an object definition, instead the function pointer is passed
1386 * directly and can be overriden by derived classes with
1387 * g_signal_override_class_closure() or
1388 * g_signal_override_class_handler()and chained to with
1389 * g_signal_chain_from_overridden() or
1390 * g_signal_chain_from_overridden_handler().
1392 * See g_signal_new() for information about signal names.
1394 * If c_marshaller is %NULL @g_cclosure_marshal_generic will be used as
1395 * the marshaller for this signal.
1397 * Returns: the signal id
1402 g_signal_new_class_handler (const gchar *signal_name,
1404 GSignalFlags signal_flags,
1405 GCallback class_handler,
1406 GSignalAccumulator accumulator,
1408 GSignalCMarshaller c_marshaller,
1416 g_return_val_if_fail (signal_name != NULL, 0);
1418 va_start (args, n_params);
1420 signal_id = g_signal_new_valist (signal_name, itype, signal_flags,
1421 class_handler ? g_cclosure_new (class_handler, NULL, NULL) : NULL,
1422 accumulator, accu_data, c_marshaller,
1423 return_type, n_params, args);
1430 static inline ClassClosure*
1431 signal_find_class_closure (SignalNode *node,
1434 GBSearchArray *bsa = node->class_closure_bsa;
1441 /* cc->instance_type is 0 for default closure */
1443 key.instance_type = itype;
1444 cc = g_bsearch_array_lookup (bsa, &g_class_closure_bconfig, &key);
1445 while (!cc && key.instance_type)
1447 key.instance_type = g_type_parent (key.instance_type);
1448 cc = g_bsearch_array_lookup (bsa, &g_class_closure_bconfig, &key);
1456 static inline GClosure*
1457 signal_lookup_closure (SignalNode *node,
1458 GTypeInstance *instance)
1462 if (node->class_closure_bsa && g_bsearch_array_get_n_nodes (node->class_closure_bsa) == 1)
1464 cc = g_bsearch_array_get_nth (node->class_closure_bsa, &g_class_closure_bconfig, 0);
1465 if (cc && cc->instance_type == 0) /* check for default closure */
1468 cc = signal_find_class_closure (node, G_TYPE_FROM_INSTANCE (instance));
1469 return cc ? cc->closure : NULL;
1473 signal_add_class_closure (SignalNode *node,
1479 /* can't optimize NOP emissions with overridden class closures */
1480 node->test_class_offset = 0;
1482 if (!node->class_closure_bsa)
1483 node->class_closure_bsa = g_bsearch_array_create (&g_class_closure_bconfig);
1484 key.instance_type = itype;
1485 key.closure = g_closure_ref (closure);
1486 node->class_closure_bsa = g_bsearch_array_insert (node->class_closure_bsa,
1487 &g_class_closure_bconfig,
1489 g_closure_sink (closure);
1490 if (node->c_marshaller && closure && G_CLOSURE_NEEDS_MARSHAL (closure))
1491 g_closure_set_marshal (closure, node->c_marshaller);
1496 * @signal_name: the name for the signal
1497 * @itype: the type this signal pertains to. It will also pertain to
1498 * types which are derived from this type
1499 * @signal_flags: a combination of #GSignalFlags specifying detail of when
1500 * the default handler is to be invoked. You should at least specify
1501 * %G_SIGNAL_RUN_FIRST or %G_SIGNAL_RUN_LAST
1502 * @class_closure: (allow-none): The closure to invoke on signal emission;
1504 * @accumulator: (allow-none): the accumulator for this signal; may be %NULL
1505 * @accu_data: user data for the @accumulator
1506 * @c_marshaller: (allow-none): the function to translate arrays of
1507 * parameter values to signal emissions into C language callback
1508 * invocations or %NULL
1509 * @return_type: the type of return value, or #G_TYPE_NONE for a signal
1510 * without a return value
1511 * @n_params: the length of @param_types
1512 * @param_types: (array length=n_params): an array of types, one for
1515 * Creates a new signal. (This is usually done in the class initializer.)
1517 * See g_signal_new() for details on allowed signal names.
1519 * If c_marshaller is %NULL @g_cclosure_marshal_generic will be used as
1520 * the marshaller for this signal.
1522 * Returns: the signal id
1525 g_signal_newv (const gchar *signal_name,
1527 GSignalFlags signal_flags,
1528 GClosure *class_closure,
1529 GSignalAccumulator accumulator,
1531 GSignalCMarshaller c_marshaller,
1540 g_return_val_if_fail (signal_name != NULL, 0);
1541 g_return_val_if_fail (G_TYPE_IS_INSTANTIATABLE (itype) || G_TYPE_IS_INTERFACE (itype), 0);
1543 g_return_val_if_fail (param_types != NULL, 0);
1544 g_return_val_if_fail ((return_type & G_SIGNAL_TYPE_STATIC_SCOPE) == 0, 0);
1545 if (return_type == (G_TYPE_NONE & ~G_SIGNAL_TYPE_STATIC_SCOPE))
1546 g_return_val_if_fail (accumulator == NULL, 0);
1548 g_return_val_if_fail (accu_data == NULL, 0);
1550 name = g_strdup (signal_name);
1551 g_strdelimit (name, G_STR_DELIMITERS ":^", '_'); /* FIXME do character checks like for types */
1555 signal_id = signal_id_lookup (g_quark_try_string (name), itype);
1556 node = LOOKUP_SIGNAL_NODE (signal_id);
1557 if (node && !node->destroyed)
1559 g_warning (G_STRLOC ": signal \"%s\" already exists in the `%s' %s",
1561 type_debug_name (node->itype),
1562 G_TYPE_IS_INTERFACE (node->itype) ? "interface" : "class ancestry");
1567 if (node && node->itype != itype)
1569 g_warning (G_STRLOC ": signal \"%s\" for type `%s' was previously created for type `%s'",
1571 type_debug_name (itype),
1572 type_debug_name (node->itype));
1577 for (i = 0; i < n_params; i++)
1578 if (!G_TYPE_IS_VALUE (param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE))
1580 g_warning (G_STRLOC ": parameter %d of type `%s' for signal \"%s::%s\" is not a value type",
1581 i + 1, type_debug_name (param_types[i]), type_debug_name (itype), name);
1586 if (return_type != G_TYPE_NONE && !G_TYPE_IS_VALUE (return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE))
1588 g_warning (G_STRLOC ": return value of type `%s' for signal \"%s::%s\" is not a value type",
1589 type_debug_name (return_type), type_debug_name (itype), name);
1594 if (return_type != G_TYPE_NONE &&
1595 (signal_flags & (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST | G_SIGNAL_RUN_CLEANUP)) == G_SIGNAL_RUN_FIRST)
1597 g_warning (G_STRLOC ": signal \"%s::%s\" has return type `%s' and is only G_SIGNAL_RUN_FIRST",
1598 type_debug_name (itype), name, type_debug_name (return_type));
1604 /* setup permanent portion of signal node */
1609 signal_id = g_n_signal_nodes++;
1610 node = g_new (SignalNode, 1);
1611 node->signal_id = signal_id;
1612 g_signal_nodes = g_renew (SignalNode*, g_signal_nodes, g_n_signal_nodes);
1613 g_signal_nodes[signal_id] = node;
1614 node->itype = itype;
1617 key.quark = g_quark_from_string (node->name);
1618 key.signal_id = signal_id;
1619 g_signal_key_bsa = g_bsearch_array_insert (g_signal_key_bsa, &g_signal_key_bconfig, &key);
1620 g_strdelimit (name, "_", '-');
1621 node->name = g_intern_string (name);
1622 key.quark = g_quark_from_string (name);
1623 g_signal_key_bsa = g_bsearch_array_insert (g_signal_key_bsa, &g_signal_key_bconfig, &key);
1625 TRACE(GOBJECT_SIGNAL_NEW(signal_id, name, itype));
1627 node->destroyed = FALSE;
1628 node->test_class_offset = 0;
1630 /* setup reinitializable portion */
1631 node->flags = signal_flags & G_SIGNAL_FLAGS_MASK;
1632 node->n_params = n_params;
1633 node->param_types = g_memdup (param_types, sizeof (GType) * n_params);
1634 node->return_type = return_type;
1635 node->class_closure_bsa = NULL;
1638 node->accumulator = g_new (SignalAccumulator, 1);
1639 node->accumulator->func = accumulator;
1640 node->accumulator->data = accu_data;
1643 node->accumulator = NULL;
1644 if (c_marshaller == NULL)
1645 c_marshaller = g_cclosure_marshal_generic;
1646 node->c_marshaller = c_marshaller;
1647 node->emission_hooks = NULL;
1649 signal_add_class_closure (node, 0, class_closure);
1650 else if (G_TYPE_IS_INSTANTIATABLE (itype) &&
1651 return_type == G_TYPE_NONE &&
1652 ~signal_flags & G_SIGNAL_MUST_COLLECT)
1654 /* optimize NOP emissions */
1655 node->test_class_offset = TEST_CLASS_MAGIC;
1665 * g_signal_new_valist:
1666 * @signal_name: the name for the signal
1667 * @itype: the type this signal pertains to. It will also pertain to
1668 * types which are derived from this type.
1669 * @signal_flags: a combination of #GSignalFlags specifying detail of when
1670 * the default handler is to be invoked. You should at least specify
1671 * %G_SIGNAL_RUN_FIRST or %G_SIGNAL_RUN_LAST.
1672 * @class_closure: The closure to invoke on signal emission; may be %NULL.
1673 * @accumulator: the accumulator for this signal; may be %NULL.
1674 * @accu_data: user data for the @accumulator.
1675 * @c_marshaller: (allow-none): the function to translate arrays of parameter
1676 * values to signal emissions into C language callback invocations or %NULL.
1677 * @return_type: the type of return value, or #G_TYPE_NONE for a signal
1678 * without a return value.
1679 * @n_params: the number of parameter types in @args.
1680 * @args: va_list of #GType, one for each parameter.
1682 * Creates a new signal. (This is usually done in the class initializer.)
1684 * See g_signal_new() for details on allowed signal names.
1686 * If c_marshaller is %NULL, g_cclosure_marshal_generic() will be used as
1687 * the marshaller for this signal.
1689 * Returns: the signal id
1692 g_signal_new_valist (const gchar *signal_name,
1694 GSignalFlags signal_flags,
1695 GClosure *class_closure,
1696 GSignalAccumulator accumulator,
1698 GSignalCMarshaller c_marshaller,
1709 param_types = g_new (GType, n_params);
1711 for (i = 0; i < n_params; i++)
1712 param_types[i] = va_arg (args, GType);
1717 signal_id = g_signal_newv (signal_name, itype, signal_flags,
1718 class_closure, accumulator, accu_data, c_marshaller,
1719 return_type, n_params, param_types);
1720 g_free (param_types);
1726 signal_destroy_R (SignalNode *signal_node)
1728 SignalNode node = *signal_node;
1730 signal_node->destroyed = TRUE;
1732 /* reentrancy caution, zero out real contents first */
1733 signal_node->test_class_offset = 0;
1734 signal_node->n_params = 0;
1735 signal_node->param_types = NULL;
1736 signal_node->return_type = 0;
1737 signal_node->class_closure_bsa = NULL;
1738 signal_node->accumulator = NULL;
1739 signal_node->c_marshaller = NULL;
1740 signal_node->emission_hooks = NULL;
1742 #ifdef G_ENABLE_DEBUG
1743 /* check current emissions */
1747 for (emission = (node.flags & G_SIGNAL_NO_RECURSE) ? g_restart_emissions : g_recursive_emissions;
1748 emission; emission = emission->next)
1749 if (emission->ihint.signal_id == node.signal_id)
1750 g_critical (G_STRLOC ": signal \"%s\" being destroyed is currently in emission (instance `%p')",
1751 node.name, emission->instance);
1755 /* free contents that need to
1758 g_free (node.param_types);
1759 if (node.class_closure_bsa)
1763 for (i = 0; i < node.class_closure_bsa->n_nodes; i++)
1765 ClassClosure *cc = g_bsearch_array_get_nth (node.class_closure_bsa, &g_class_closure_bconfig, i);
1767 g_closure_unref (cc->closure);
1769 g_bsearch_array_free (node.class_closure_bsa, &g_class_closure_bconfig);
1771 g_free (node.accumulator);
1772 if (node.emission_hooks)
1774 g_hook_list_clear (node.emission_hooks);
1775 g_free (node.emission_hooks);
1781 * g_signal_override_class_closure:
1782 * @signal_id: the signal id
1783 * @instance_type: the instance type on which to override the class closure
1785 * @class_closure: the closure.
1787 * Overrides the class closure (i.e. the default handler) for the given signal
1788 * for emissions on instances of @instance_type. @instance_type must be derived
1789 * from the type to which the signal belongs.
1791 * See g_signal_chain_from_overridden() and
1792 * g_signal_chain_from_overridden_handler() for how to chain up to the
1793 * parent class closure from inside the overridden one.
1796 g_signal_override_class_closure (guint signal_id,
1797 GType instance_type,
1798 GClosure *class_closure)
1802 g_return_if_fail (signal_id > 0);
1803 g_return_if_fail (class_closure != NULL);
1806 node = LOOKUP_SIGNAL_NODE (signal_id);
1807 if (!g_type_is_a (instance_type, node->itype))
1808 g_warning ("%s: type `%s' cannot be overridden for signal id `%u'", G_STRLOC, type_debug_name (instance_type), signal_id);
1811 ClassClosure *cc = signal_find_class_closure (node, instance_type);
1813 if (cc && cc->instance_type == instance_type)
1814 g_warning ("%s: type `%s' is already overridden for signal id `%u'", G_STRLOC, type_debug_name (instance_type), signal_id);
1816 signal_add_class_closure (node, instance_type, class_closure);
1822 * g_signal_override_class_handler:
1823 * @signal_name: the name for the signal
1824 * @instance_type: the instance type on which to override the class handler
1826 * @class_handler: the handler.
1828 * Overrides the class closure (i.e. the default handler) for the
1829 * given signal for emissions on instances of @instance_type with
1830 * callabck @class_handler. @instance_type must be derived from the
1831 * type to which the signal belongs.
1833 * See g_signal_chain_from_overridden() and
1834 * g_signal_chain_from_overridden_handler() for how to chain up to the
1835 * parent class closure from inside the overridden one.
1840 g_signal_override_class_handler (const gchar *signal_name,
1841 GType instance_type,
1842 GCallback class_handler)
1846 g_return_if_fail (signal_name != NULL);
1847 g_return_if_fail (instance_type != G_TYPE_NONE);
1848 g_return_if_fail (class_handler != NULL);
1850 signal_id = g_signal_lookup (signal_name, instance_type);
1853 g_signal_override_class_closure (signal_id, instance_type,
1854 g_cclosure_new (class_handler, NULL, NULL));
1856 g_warning ("%s: signal name '%s' is invalid for type id '%"G_GSIZE_FORMAT"'",
1857 G_STRLOC, signal_name, instance_type);
1862 * g_signal_chain_from_overridden:
1863 * @instance_and_params: (array) the argument list of the signal emission.
1864 * The first element in the array is a #GValue for the instance the signal
1865 * is being emitted on. The rest are any arguments to be passed to the signal.
1866 * @return_value: Location for the return value.
1868 * Calls the original class closure of a signal. This function should only
1869 * be called from an overridden class closure; see
1870 * g_signal_override_class_closure() and
1871 * g_signal_override_class_handler().
1874 g_signal_chain_from_overridden (const GValue *instance_and_params,
1875 GValue *return_value)
1877 GType chain_type = 0, restore_type = 0;
1878 Emission *emission = NULL;
1879 GClosure *closure = NULL;
1883 g_return_if_fail (instance_and_params != NULL);
1884 instance = g_value_peek_pointer (instance_and_params);
1885 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
1888 emission = emission_find_innermost (instance);
1891 SignalNode *node = LOOKUP_SIGNAL_NODE (emission->ihint.signal_id);
1893 g_assert (node != NULL); /* paranoid */
1895 /* we should probably do the same parameter checks as g_signal_emit() here.
1897 if (emission->chain_type != G_TYPE_NONE)
1899 ClassClosure *cc = signal_find_class_closure (node, emission->chain_type);
1901 g_assert (cc != NULL); /* closure currently in call stack */
1903 n_params = node->n_params;
1904 restore_type = cc->instance_type;
1905 cc = signal_find_class_closure (node, g_type_parent (cc->instance_type));
1906 if (cc && cc->instance_type != restore_type)
1908 closure = cc->closure;
1909 chain_type = cc->instance_type;
1913 g_warning ("%s: signal id `%u' cannot be chained from current emission stage for instance `%p'", G_STRLOC, node->signal_id, instance);
1916 g_warning ("%s: no signal is currently being emitted for instance `%p'", G_STRLOC, instance);
1920 emission->chain_type = chain_type;
1922 g_closure_invoke (closure,
1925 instance_and_params,
1928 emission->chain_type = restore_type;
1934 * g_signal_chain_from_overridden_handler:
1935 * @instance: the instance the signal is being emitted on.
1936 * @...: parameters to be passed to the parent class closure, followed by a
1937 * location for the return value. If the return type of the signal
1938 * is #G_TYPE_NONE, the return value location can be omitted.
1940 * Calls the original class closure of a signal. This function should
1941 * only be called from an overridden class closure; see
1942 * g_signal_override_class_closure() and
1943 * g_signal_override_class_handler().
1948 g_signal_chain_from_overridden_handler (gpointer instance,
1951 GType chain_type = 0, restore_type = 0;
1952 Emission *emission = NULL;
1953 GClosure *closure = NULL;
1957 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
1960 emission = emission_find_innermost (instance);
1963 node = LOOKUP_SIGNAL_NODE (emission->ihint.signal_id);
1965 g_assert (node != NULL); /* paranoid */
1967 /* we should probably do the same parameter checks as g_signal_emit() here.
1969 if (emission->chain_type != G_TYPE_NONE)
1971 ClassClosure *cc = signal_find_class_closure (node, emission->chain_type);
1973 g_assert (cc != NULL); /* closure currently in call stack */
1975 n_params = node->n_params;
1976 restore_type = cc->instance_type;
1977 cc = signal_find_class_closure (node, g_type_parent (cc->instance_type));
1978 if (cc && cc->instance_type != restore_type)
1980 closure = cc->closure;
1981 chain_type = cc->instance_type;
1985 g_warning ("%s: signal id `%u' cannot be chained from current emission stage for instance `%p'", G_STRLOC, node->signal_id, instance);
1988 g_warning ("%s: no signal is currently being emitted for instance `%p'", G_STRLOC, instance);
1992 GValue *instance_and_params;
1993 GType signal_return_type;
1994 GValue *param_values;
1998 va_start (var_args, instance);
2000 signal_return_type = node->return_type;
2001 instance_and_params = g_slice_alloc0 (sizeof (GValue) * (n_params + 1));
2002 param_values = instance_and_params + 1;
2004 for (i = 0; i < node->n_params; i++)
2007 GType ptype = node->param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE;
2008 gboolean static_scope = node->param_types[i] & G_SIGNAL_TYPE_STATIC_SCOPE;
2011 G_VALUE_COLLECT_INIT (param_values + i, ptype,
2013 static_scope ? G_VALUE_NOCOPY_CONTENTS : 0,
2017 g_warning ("%s: %s", G_STRLOC, error);
2020 /* we purposely leak the value here, it might not be
2021 * in a sane state if an error condition occoured
2024 g_value_unset (param_values + i);
2026 g_slice_free1 (sizeof (GValue) * (n_params + 1), instance_and_params);
2034 instance_and_params->g_type = 0;
2035 g_value_init (instance_and_params, G_TYPE_FROM_INSTANCE (instance));
2036 g_value_set_instance (instance_and_params, instance);
2039 emission->chain_type = chain_type;
2042 if (signal_return_type == G_TYPE_NONE)
2044 g_closure_invoke (closure,
2047 instance_and_params,
2052 GValue return_value = { 0, };
2053 gchar *error = NULL;
2054 GType rtype = signal_return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE;
2055 gboolean static_scope = signal_return_type & G_SIGNAL_TYPE_STATIC_SCOPE;
2057 g_value_init (&return_value, rtype);
2059 g_closure_invoke (closure,
2062 instance_and_params,
2065 G_VALUE_LCOPY (&return_value,
2067 static_scope ? G_VALUE_NOCOPY_CONTENTS : 0,
2071 g_value_unset (&return_value);
2075 g_warning ("%s: %s", G_STRLOC, error);
2078 /* we purposely leak the value here, it might not be
2079 * in a sane state if an error condition occurred
2084 for (i = 0; i < n_params; i++)
2085 g_value_unset (param_values + i);
2086 g_value_unset (instance_and_params);
2087 g_slice_free1 (sizeof (GValue) * (n_params + 1), instance_and_params);
2092 emission->chain_type = restore_type;
2098 * g_signal_get_invocation_hint:
2099 * @instance: the instance to query
2101 * Returns the invocation hint of the innermost signal emission of instance.
2103 * Returns: (transfer none): the invocation hint of the innermost signal emission.
2105 GSignalInvocationHint*
2106 g_signal_get_invocation_hint (gpointer instance)
2108 Emission *emission = NULL;
2110 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), NULL);
2113 emission = emission_find_innermost (instance);
2116 return emission ? &emission->ihint : NULL;
2120 * g_signal_connect_closure_by_id:
2121 * @instance: the instance to connect to.
2122 * @signal_id: the id of the signal.
2123 * @detail: the detail.
2124 * @closure: the closure to connect.
2125 * @after: whether the handler should be called before or after the
2126 * default handler of the signal.
2128 * Connects a closure to a signal for a particular object.
2130 * Returns: the handler id
2133 g_signal_connect_closure_by_id (gpointer instance,
2140 gulong handler_seq_no = 0;
2142 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
2143 g_return_val_if_fail (signal_id > 0, 0);
2144 g_return_val_if_fail (closure != NULL, 0);
2147 node = LOOKUP_SIGNAL_NODE (signal_id);
2150 if (detail && !(node->flags & G_SIGNAL_DETAILED))
2151 g_warning ("%s: signal id `%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
2152 else if (!g_type_is_a (G_TYPE_FROM_INSTANCE (instance), node->itype))
2153 g_warning ("%s: signal id `%u' is invalid for instance `%p'", G_STRLOC, signal_id, instance);
2156 Handler *handler = handler_new (after);
2158 handler_seq_no = handler->sequential_number;
2159 handler->detail = detail;
2160 handler->closure = g_closure_ref (closure);
2161 g_closure_sink (closure);
2162 handler_insert (signal_id, instance, handler);
2163 if (node->c_marshaller && G_CLOSURE_NEEDS_MARSHAL (closure))
2164 g_closure_set_marshal (closure, node->c_marshaller);
2168 g_warning ("%s: signal id `%u' is invalid for instance `%p'", G_STRLOC, signal_id, instance);
2171 return handler_seq_no;
2175 * g_signal_connect_closure:
2176 * @instance: the instance to connect to.
2177 * @detailed_signal: a string of the form "signal-name::detail".
2178 * @closure: the closure to connect.
2179 * @after: whether the handler should be called before or after the
2180 * default handler of the signal.
2182 * Connects a closure to a signal for a particular object.
2184 * Returns: the handler id
2187 g_signal_connect_closure (gpointer instance,
2188 const gchar *detailed_signal,
2193 gulong handler_seq_no = 0;
2197 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
2198 g_return_val_if_fail (detailed_signal != NULL, 0);
2199 g_return_val_if_fail (closure != NULL, 0);
2202 itype = G_TYPE_FROM_INSTANCE (instance);
2203 signal_id = signal_parse_name (detailed_signal, itype, &detail, TRUE);
2206 SignalNode *node = LOOKUP_SIGNAL_NODE (signal_id);
2208 if (detail && !(node->flags & G_SIGNAL_DETAILED))
2209 g_warning ("%s: signal `%s' does not support details", G_STRLOC, detailed_signal);
2210 else if (!g_type_is_a (itype, node->itype))
2211 g_warning ("%s: signal `%s' is invalid for instance `%p'", G_STRLOC, detailed_signal, instance);
2214 Handler *handler = handler_new (after);
2216 handler_seq_no = handler->sequential_number;
2217 handler->detail = detail;
2218 handler->closure = g_closure_ref (closure);
2219 g_closure_sink (closure);
2220 handler_insert (signal_id, instance, handler);
2221 if (node->c_marshaller && G_CLOSURE_NEEDS_MARSHAL (handler->closure))
2222 g_closure_set_marshal (handler->closure, node->c_marshaller);
2226 g_warning ("%s: signal `%s' is invalid for instance `%p'", G_STRLOC, detailed_signal, instance);
2229 return handler_seq_no;
2233 * g_signal_connect_data:
2234 * @instance: the instance to connect to.
2235 * @detailed_signal: a string of the form "signal-name::detail".
2236 * @c_handler: the #GCallback to connect.
2237 * @data: data to pass to @c_handler calls.
2238 * @destroy_data: a #GClosureNotify for @data.
2239 * @connect_flags: a combination of #GConnectFlags.
2241 * Connects a #GCallback function to a signal for a particular object. Similar
2242 * to g_signal_connect(), but allows to provide a #GClosureNotify for the data
2243 * which will be called when the signal handler is disconnected and no longer
2244 * used. Specify @connect_flags if you need <literal>..._after()</literal> or
2245 * <literal>..._swapped()</literal> variants of this function.
2247 * Returns: the handler id
2250 g_signal_connect_data (gpointer instance,
2251 const gchar *detailed_signal,
2252 GCallback c_handler,
2254 GClosureNotify destroy_data,
2255 GConnectFlags connect_flags)
2258 gulong handler_seq_no = 0;
2261 gboolean swapped, after;
2263 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
2264 g_return_val_if_fail (detailed_signal != NULL, 0);
2265 g_return_val_if_fail (c_handler != NULL, 0);
2267 swapped = (connect_flags & G_CONNECT_SWAPPED) != FALSE;
2268 after = (connect_flags & G_CONNECT_AFTER) != FALSE;
2271 itype = G_TYPE_FROM_INSTANCE (instance);
2272 signal_id = signal_parse_name (detailed_signal, itype, &detail, TRUE);
2275 SignalNode *node = LOOKUP_SIGNAL_NODE (signal_id);
2277 if (detail && !(node->flags & G_SIGNAL_DETAILED))
2278 g_warning ("%s: signal `%s' does not support details", G_STRLOC, detailed_signal);
2279 else if (!g_type_is_a (itype, node->itype))
2280 g_warning ("%s: signal `%s' is invalid for instance `%p'", G_STRLOC, detailed_signal, instance);
2283 Handler *handler = handler_new (after);
2285 handler_seq_no = handler->sequential_number;
2286 handler->detail = detail;
2287 handler->closure = g_closure_ref ((swapped ? g_cclosure_new_swap : g_cclosure_new) (c_handler, data, destroy_data));
2288 g_closure_sink (handler->closure);
2289 handler_insert (signal_id, instance, handler);
2290 if (node->c_marshaller && G_CLOSURE_NEEDS_MARSHAL (handler->closure))
2291 g_closure_set_marshal (handler->closure, node->c_marshaller);
2295 g_warning ("%s: signal `%s' is invalid for instance `%p'", G_STRLOC, detailed_signal, instance);
2298 return handler_seq_no;
2302 * g_signal_handler_block:
2303 * @instance: The instance to block the signal handler of.
2304 * @handler_id: Handler id of the handler to be blocked.
2306 * Blocks a handler of an instance so it will not be called during any
2307 * signal emissions unless it is unblocked again. Thus "blocking" a
2308 * signal handler means to temporarily deactive it, a signal handler
2309 * has to be unblocked exactly the same amount of times it has been
2310 * blocked before to become active again.
2312 * The @handler_id has to be a valid signal handler id, connected to a
2313 * signal of @instance.
2316 g_signal_handler_block (gpointer instance,
2321 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
2322 g_return_if_fail (handler_id > 0);
2325 handler = handler_lookup (instance, handler_id, NULL);
2328 #ifndef G_DISABLE_CHECKS
2329 if (handler->block_count >= HANDLER_MAX_BLOCK_COUNT - 1)
2330 g_error (G_STRLOC ": handler block_count overflow, %s", REPORT_BUG);
2332 handler->block_count += 1;
2335 g_warning ("%s: instance `%p' has no handler with id `%lu'", G_STRLOC, instance, handler_id);
2340 * g_signal_handler_unblock:
2341 * @instance: The instance to unblock the signal handler of.
2342 * @handler_id: Handler id of the handler to be unblocked.
2344 * Undoes the effect of a previous g_signal_handler_block() call. A
2345 * blocked handler is skipped during signal emissions and will not be
2346 * invoked, unblocking it (for exactly the amount of times it has been
2347 * blocked before) reverts its "blocked" state, so the handler will be
2348 * recognized by the signal system and is called upon future or
2349 * currently ongoing signal emissions (since the order in which
2350 * handlers are called during signal emissions is deterministic,
2351 * whether the unblocked handler in question is called as part of a
2352 * currently ongoing emission depends on how far that emission has
2355 * The @handler_id has to be a valid id of a signal handler that is
2356 * connected to a signal of @instance and is currently blocked.
2359 g_signal_handler_unblock (gpointer instance,
2364 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
2365 g_return_if_fail (handler_id > 0);
2368 handler = handler_lookup (instance, handler_id, NULL);
2371 if (handler->block_count)
2372 handler->block_count -= 1;
2374 g_warning (G_STRLOC ": handler `%lu' of instance `%p' is not blocked", handler_id, instance);
2377 g_warning ("%s: instance `%p' has no handler with id `%lu'", G_STRLOC, instance, handler_id);
2382 * g_signal_handler_disconnect:
2383 * @instance: The instance to remove the signal handler from.
2384 * @handler_id: Handler id of the handler to be disconnected.
2386 * Disconnects a handler from an instance so it will not be called during
2387 * any future or currently ongoing emissions of the signal it has been
2388 * connected to. The @handler_id becomes invalid and may be reused.
2390 * The @handler_id has to be a valid signal handler id, connected to a
2391 * signal of @instance.
2394 g_signal_handler_disconnect (gpointer instance,
2400 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
2401 g_return_if_fail (handler_id > 0);
2404 handler = handler_lookup (instance, handler_id, &signal_id);
2407 handler->sequential_number = 0;
2408 handler->block_count = 1;
2409 handler_unref_R (signal_id, instance, handler);
2412 g_warning ("%s: instance `%p' has no handler with id `%lu'", G_STRLOC, instance, handler_id);
2417 * g_signal_handler_is_connected:
2418 * @instance: The instance where a signal handler is sought.
2419 * @handler_id: the handler id.
2421 * Returns whether @handler_id is the id of a handler connected to @instance.
2423 * Returns: whether @handler_id identifies a handler connected to @instance.
2426 g_signal_handler_is_connected (gpointer instance,
2432 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), FALSE);
2435 handler = handler_lookup (instance, handler_id, NULL);
2436 connected = handler != NULL;
2443 g_signal_handlers_destroy (gpointer instance)
2445 GBSearchArray *hlbsa;
2447 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
2450 hlbsa = g_hash_table_lookup (g_handler_list_bsa_ht, instance);
2455 /* reentrancy caution, delete instance trace first */
2456 g_hash_table_remove (g_handler_list_bsa_ht, instance);
2458 for (i = 0; i < hlbsa->n_nodes; i++)
2460 HandlerList *hlist = g_bsearch_array_get_nth (hlbsa, &g_signal_hlbsa_bconfig, i);
2461 Handler *handler = hlist->handlers;
2465 Handler *tmp = handler;
2467 handler = tmp->next;
2468 tmp->block_count = 1;
2469 /* cruel unlink, this works because _all_ handlers vanish */
2472 if (tmp->sequential_number)
2474 tmp->sequential_number = 0;
2475 handler_unref_R (0, NULL, tmp);
2479 g_bsearch_array_free (hlbsa, &g_signal_hlbsa_bconfig);
2485 * g_signal_handler_find:
2486 * @instance: The instance owning the signal handler to be found.
2487 * @mask: Mask indicating which of @signal_id, @detail, @closure, @func
2488 * and/or @data the handler has to match.
2489 * @signal_id: Signal the handler has to be connected to.
2490 * @detail: Signal detail the handler has to be connected to.
2491 * @closure: (allow-none): The closure the handler will invoke.
2492 * @func: The C closure callback of the handler (useless for non-C closures).
2493 * @data: The closure data of the handler's closure.
2495 * Finds the first signal handler that matches certain selection criteria.
2496 * The criteria mask is passed as an OR-ed combination of #GSignalMatchType
2497 * flags, and the criteria values are passed as arguments.
2498 * The match @mask has to be non-0 for successful matches.
2499 * If no handler was found, 0 is returned.
2501 * Returns: A valid non-0 signal handler id for a successful match.
2504 g_signal_handler_find (gpointer instance,
2505 GSignalMatchType mask,
2512 gulong handler_seq_no = 0;
2514 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
2515 g_return_val_if_fail ((mask & ~G_SIGNAL_MATCH_MASK) == 0, 0);
2517 if (mask & G_SIGNAL_MATCH_MASK)
2519 HandlerMatch *mlist;
2522 mlist = handlers_find (instance, mask, signal_id, detail, closure, func, data, TRUE);
2525 handler_seq_no = mlist->handler->sequential_number;
2526 handler_match_free1_R (mlist, instance);
2531 return handler_seq_no;
2535 signal_handlers_foreach_matched_R (gpointer instance,
2536 GSignalMatchType mask,
2542 void (*callback) (gpointer instance,
2543 gulong handler_seq_no))
2545 HandlerMatch *mlist;
2546 guint n_handlers = 0;
2548 mlist = handlers_find (instance, mask, signal_id, detail, closure, func, data, FALSE);
2552 if (mlist->handler->sequential_number)
2555 callback (instance, mlist->handler->sequential_number);
2558 mlist = handler_match_free1_R (mlist, instance);
2565 * g_signal_handlers_block_matched:
2566 * @instance: The instance to block handlers from.
2567 * @mask: Mask indicating which of @signal_id, @detail, @closure, @func
2568 * and/or @data the handlers have to match.
2569 * @signal_id: Signal the handlers have to be connected to.
2570 * @detail: Signal detail the handlers have to be connected to.
2571 * @closure: (allow-none): The closure the handlers will invoke.
2572 * @func: The C closure callback of the handlers (useless for non-C closures).
2573 * @data: The closure data of the handlers' closures.
2575 * Blocks all handlers on an instance that match a certain selection criteria.
2576 * The criteria mask is passed as an OR-ed combination of #GSignalMatchType
2577 * flags, and the criteria values are passed as arguments.
2578 * Passing at least one of the %G_SIGNAL_MATCH_CLOSURE, %G_SIGNAL_MATCH_FUNC
2579 * or %G_SIGNAL_MATCH_DATA match flags is required for successful matches.
2580 * If no handlers were found, 0 is returned, the number of blocked handlers
2583 * Returns: The number of handlers that matched.
2586 g_signal_handlers_block_matched (gpointer instance,
2587 GSignalMatchType mask,
2594 guint n_handlers = 0;
2596 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
2597 g_return_val_if_fail ((mask & ~G_SIGNAL_MATCH_MASK) == 0, 0);
2599 if (mask & (G_SIGNAL_MATCH_CLOSURE | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA))
2602 n_handlers = signal_handlers_foreach_matched_R (instance, mask, signal_id, detail,
2603 closure, func, data,
2604 g_signal_handler_block);
2612 * g_signal_handlers_unblock_matched:
2613 * @instance: The instance to unblock handlers from.
2614 * @mask: Mask indicating which of @signal_id, @detail, @closure, @func
2615 * and/or @data the handlers have to match.
2616 * @signal_id: Signal the handlers have to be connected to.
2617 * @detail: Signal detail the handlers have to be connected to.
2618 * @closure: (allow-none): The closure the handlers will invoke.
2619 * @func: The C closure callback of the handlers (useless for non-C closures).
2620 * @data: The closure data of the handlers' closures.
2622 * Unblocks all handlers on an instance that match a certain selection
2623 * criteria. The criteria mask is passed as an OR-ed combination of
2624 * #GSignalMatchType flags, and the criteria values are passed as arguments.
2625 * Passing at least one of the %G_SIGNAL_MATCH_CLOSURE, %G_SIGNAL_MATCH_FUNC
2626 * or %G_SIGNAL_MATCH_DATA match flags is required for successful matches.
2627 * If no handlers were found, 0 is returned, the number of unblocked handlers
2628 * otherwise. The match criteria should not apply to any handlers that are
2629 * not currently blocked.
2631 * Returns: The number of handlers that matched.
2634 g_signal_handlers_unblock_matched (gpointer instance,
2635 GSignalMatchType mask,
2642 guint n_handlers = 0;
2644 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
2645 g_return_val_if_fail ((mask & ~G_SIGNAL_MATCH_MASK) == 0, 0);
2647 if (mask & (G_SIGNAL_MATCH_CLOSURE | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA))
2650 n_handlers = signal_handlers_foreach_matched_R (instance, mask, signal_id, detail,
2651 closure, func, data,
2652 g_signal_handler_unblock);
2660 * g_signal_handlers_disconnect_matched:
2661 * @instance: The instance to remove handlers from.
2662 * @mask: Mask indicating which of @signal_id, @detail, @closure, @func
2663 * and/or @data the handlers have to match.
2664 * @signal_id: Signal the handlers have to be connected to.
2665 * @detail: Signal detail the handlers have to be connected to.
2666 * @closure: (allow-none): The closure the handlers will invoke.
2667 * @func: The C closure callback of the handlers (useless for non-C closures).
2668 * @data: The closure data of the handlers' closures.
2670 * Disconnects all handlers on an instance that match a certain
2671 * selection criteria. The criteria mask is passed as an OR-ed
2672 * combination of #GSignalMatchType flags, and the criteria values are
2673 * passed as arguments. Passing at least one of the
2674 * %G_SIGNAL_MATCH_CLOSURE, %G_SIGNAL_MATCH_FUNC or
2675 * %G_SIGNAL_MATCH_DATA match flags is required for successful
2676 * matches. If no handlers were found, 0 is returned, the number of
2677 * disconnected handlers otherwise.
2679 * Returns: The number of handlers that matched.
2682 g_signal_handlers_disconnect_matched (gpointer instance,
2683 GSignalMatchType mask,
2690 guint n_handlers = 0;
2692 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
2693 g_return_val_if_fail ((mask & ~G_SIGNAL_MATCH_MASK) == 0, 0);
2695 if (mask & (G_SIGNAL_MATCH_CLOSURE | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA))
2698 n_handlers = signal_handlers_foreach_matched_R (instance, mask, signal_id, detail,
2699 closure, func, data,
2700 g_signal_handler_disconnect);
2708 * g_signal_has_handler_pending:
2709 * @instance: the object whose signal handlers are sought.
2710 * @signal_id: the signal id.
2711 * @detail: the detail.
2712 * @may_be_blocked: whether blocked handlers should count as match.
2714 * Returns whether there are any handlers connected to @instance for the
2715 * given signal id and detail.
2717 * One example of when you might use this is when the arguments to the
2718 * signal are difficult to compute. A class implementor may opt to not
2719 * emit the signal if no one is attached anyway, thus saving the cost
2720 * of building the arguments.
2722 * Returns: %TRUE if a handler is connected to the signal, %FALSE
2726 g_signal_has_handler_pending (gpointer instance,
2729 gboolean may_be_blocked)
2731 HandlerMatch *mlist;
2732 gboolean has_pending;
2734 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), FALSE);
2735 g_return_val_if_fail (signal_id > 0, FALSE);
2740 SignalNode *node = LOOKUP_SIGNAL_NODE (signal_id);
2742 if (!(node->flags & G_SIGNAL_DETAILED))
2744 g_warning ("%s: signal id `%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
2749 mlist = handlers_find (instance,
2750 (G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | (may_be_blocked ? 0 : G_SIGNAL_MATCH_UNBLOCKED)),
2751 signal_id, detail, NULL, NULL, NULL, TRUE);
2755 handler_match_free1_R (mlist, instance);
2758 has_pending = FALSE;
2764 static inline gboolean
2765 signal_check_skip_emission (SignalNode *node,
2771 /* are we able to check for NULL class handlers? */
2772 if (!node->test_class_offset)
2775 /* are there emission hooks pending? */
2776 if (node->emission_hooks && node->emission_hooks->hooks)
2779 /* is there a non-NULL class handler? */
2780 if (node->test_class_offset != TEST_CLASS_MAGIC)
2782 GTypeClass *class = G_TYPE_INSTANCE_GET_CLASS (instance, G_TYPE_FROM_INSTANCE (instance), GTypeClass);
2784 if (G_STRUCT_MEMBER (gpointer, class, node->test_class_offset))
2788 /* are signals being debugged? */
2789 #ifdef G_ENABLE_DEBUG
2790 IF_DEBUG (SIGNALS, g_trace_instance_signals || g_trap_instance_signals)
2792 #endif /* G_ENABLE_DEBUG */
2794 /* is this a no-recurse signal already in emission? */
2795 if (node->flags & G_SIGNAL_NO_RECURSE &&
2796 emission_find (g_restart_emissions, node->signal_id, detail, instance))
2799 /* do we have pending handlers? */
2800 hlist = handler_list_lookup (node->signal_id, instance);
2801 if (hlist && hlist->handlers)
2804 /* none of the above, no emission required */
2810 * @instance_and_params: (array): argument list for the signal emission.
2811 * The first element in the array is a #GValue for the instance the signal
2812 * is being emitted on. The rest are any arguments to be passed to the signal.
2813 * @signal_id: the signal id
2814 * @detail: the detail
2815 * @return_value: Location to store the return value of the signal emission.
2819 * Note that g_signal_emitv() doesn't change @return_value if no handlers are
2820 * connected, in contrast to g_signal_emit() and g_signal_emit_valist().
2823 g_signal_emitv (const GValue *instance_and_params,
2826 GValue *return_value)
2830 #ifdef G_ENABLE_DEBUG
2831 const GValue *param_values;
2835 g_return_if_fail (instance_and_params != NULL);
2836 instance = g_value_peek_pointer (instance_and_params);
2837 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
2838 g_return_if_fail (signal_id > 0);
2840 #ifdef G_ENABLE_DEBUG
2841 param_values = instance_and_params + 1;
2845 node = LOOKUP_SIGNAL_NODE (signal_id);
2846 if (!node || !g_type_is_a (G_TYPE_FROM_INSTANCE (instance), node->itype))
2848 g_warning ("%s: signal id `%u' is invalid for instance `%p'", G_STRLOC, signal_id, instance);
2852 #ifdef G_ENABLE_DEBUG
2853 if (detail && !(node->flags & G_SIGNAL_DETAILED))
2855 g_warning ("%s: signal id `%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
2859 for (i = 0; i < node->n_params; i++)
2860 if (!G_TYPE_CHECK_VALUE_TYPE (param_values + i, node->param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE))
2862 g_critical ("%s: value for `%s' parameter %u for signal \"%s\" is of type `%s'",
2864 type_debug_name (node->param_types[i]),
2867 G_VALUE_TYPE_NAME (param_values + i));
2871 if (node->return_type != G_TYPE_NONE)
2875 g_critical ("%s: return value `%s' for signal \"%s\" is (NULL)",
2877 type_debug_name (node->return_type),
2882 else if (!node->accumulator && !G_TYPE_CHECK_VALUE_TYPE (return_value, node->return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE))
2884 g_critical ("%s: return value `%s' for signal \"%s\" is of type `%s'",
2886 type_debug_name (node->return_type),
2888 G_VALUE_TYPE_NAME (return_value));
2894 return_value = NULL;
2895 #endif /* G_ENABLE_DEBUG */
2897 /* optimize NOP emissions */
2898 if (signal_check_skip_emission (node, instance, detail))
2900 /* nothing to do to emit this signal */
2902 /* g_printerr ("omitting emission of \"%s\"\n", node->name); */
2907 signal_emit_unlocked_R (node, detail, instance, return_value, instance_and_params);
2911 * g_signal_emit_valist:
2912 * @instance: the instance the signal is being emitted on.
2913 * @signal_id: the signal id
2914 * @detail: the detail
2915 * @var_args: a list of parameters to be passed to the signal, followed by a
2916 * location for the return value. If the return type of the signal
2917 * is #G_TYPE_NONE, the return value location can be omitted.
2921 * Note that g_signal_emit_valist() resets the return value to the default
2922 * if no handlers are connected, in contrast to g_signal_emitv().
2925 g_signal_emit_valist (gpointer instance,
2930 GValue *instance_and_params;
2931 GType signal_return_type;
2932 GValue *param_values;
2936 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
2937 g_return_if_fail (signal_id > 0);
2940 node = LOOKUP_SIGNAL_NODE (signal_id);
2941 if (!node || !g_type_is_a (G_TYPE_FROM_INSTANCE (instance), node->itype))
2943 g_warning ("%s: signal id `%u' is invalid for instance `%p'", G_STRLOC, signal_id, instance);
2947 #ifndef G_DISABLE_CHECKS
2948 if (detail && !(node->flags & G_SIGNAL_DETAILED))
2950 g_warning ("%s: signal id `%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
2954 #endif /* !G_DISABLE_CHECKS */
2956 /* optimize NOP emissions */
2957 if (signal_check_skip_emission (node, instance, detail))
2959 /* nothing to do to emit this signal */
2961 /* g_printerr ("omitting emission of \"%s\"\n", node->name); */
2965 n_params = node->n_params;
2966 signal_return_type = node->return_type;
2967 instance_and_params = g_slice_alloc0 (sizeof (GValue) * (n_params + 1));
2968 param_values = instance_and_params + 1;
2970 for (i = 0; i < node->n_params; i++)
2973 GType ptype = node->param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE;
2974 gboolean static_scope = node->param_types[i] & G_SIGNAL_TYPE_STATIC_SCOPE;
2977 G_VALUE_COLLECT_INIT (param_values + i, ptype,
2979 static_scope ? G_VALUE_NOCOPY_CONTENTS : 0,
2983 g_warning ("%s: %s", G_STRLOC, error);
2986 /* we purposely leak the value here, it might not be
2987 * in a sane state if an error condition occoured
2990 g_value_unset (param_values + i);
2992 g_slice_free1 (sizeof (GValue) * (n_params + 1), instance_and_params);
2999 instance_and_params->g_type = 0;
3000 g_value_init (instance_and_params, G_TYPE_FROM_INSTANCE (instance));
3001 g_value_set_instance (instance_and_params, instance);
3002 if (signal_return_type == G_TYPE_NONE)
3003 signal_emit_unlocked_R (node, detail, instance, NULL, instance_and_params);
3006 GValue return_value = { 0, };
3007 gchar *error = NULL;
3008 GType rtype = signal_return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE;
3009 gboolean static_scope = signal_return_type & G_SIGNAL_TYPE_STATIC_SCOPE;
3011 g_value_init (&return_value, rtype);
3013 signal_emit_unlocked_R (node, detail, instance, &return_value, instance_and_params);
3015 G_VALUE_LCOPY (&return_value,
3017 static_scope ? G_VALUE_NOCOPY_CONTENTS : 0,
3020 g_value_unset (&return_value);
3023 g_warning ("%s: %s", G_STRLOC, error);
3026 /* we purposely leak the value here, it might not be
3027 * in a sane state if an error condition occurred
3031 for (i = 0; i < n_params; i++)
3032 g_value_unset (param_values + i);
3033 g_value_unset (instance_and_params);
3034 g_slice_free1 (sizeof (GValue) * (n_params + 1), instance_and_params);
3039 * @instance: the instance the signal is being emitted on.
3040 * @signal_id: the signal id
3041 * @detail: the detail
3042 * @...: parameters to be passed to the signal, followed by a
3043 * location for the return value. If the return type of the signal
3044 * is #G_TYPE_NONE, the return value location can be omitted.
3048 * Note that g_signal_emit() resets the return value to the default
3049 * if no handlers are connected, in contrast to g_signal_emitv().
3052 g_signal_emit (gpointer instance,
3059 va_start (var_args, detail);
3060 g_signal_emit_valist (instance, signal_id, detail, var_args);
3065 * g_signal_emit_by_name:
3066 * @instance: the instance the signal is being emitted on.
3067 * @detailed_signal: a string of the form "signal-name::detail".
3068 * @...: parameters to be passed to the signal, followed by a
3069 * location for the return value. If the return type of the signal
3070 * is #G_TYPE_NONE, the return value location can be omitted.
3074 * Note that g_signal_emit_by_name() resets the return value to the default
3075 * if no handlers are connected, in contrast to g_signal_emitv().
3078 g_signal_emit_by_name (gpointer instance,
3079 const gchar *detailed_signal,
3085 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
3086 g_return_if_fail (detailed_signal != NULL);
3089 signal_id = signal_parse_name (detailed_signal, G_TYPE_FROM_INSTANCE (instance), &detail, TRUE);
3096 va_start (var_args, detailed_signal);
3097 g_signal_emit_valist (instance, signal_id, detail, var_args);
3101 g_warning ("%s: signal name `%s' is invalid for instance `%p'", G_STRLOC, detailed_signal, instance);
3104 static inline gboolean
3105 accumulate (GSignalInvocationHint *ihint,
3106 GValue *return_accu,
3107 GValue *handler_return,
3108 SignalAccumulator *accumulator)
3110 gboolean continue_emission;
3115 continue_emission = accumulator->func (ihint, return_accu, handler_return, accumulator->data);
3116 g_value_reset (handler_return);
3118 return continue_emission;
3122 signal_emit_unlocked_R (SignalNode *node,
3125 GValue *emission_return,
3126 const GValue *instance_and_params)
3128 SignalAccumulator *accumulator;
3130 GClosure *class_closure;
3132 Handler *handler_list = NULL;
3133 GValue *return_accu, accu = { 0, };
3135 gulong max_sequential_handler_number;
3136 gboolean return_value_altered = FALSE;
3138 #ifdef G_ENABLE_DEBUG
3139 IF_DEBUG (SIGNALS, g_trace_instance_signals == instance || g_trap_instance_signals == instance)
3141 g_message ("%s::%s(%u) emitted (instance=%p, signal-node=%p)",
3142 g_type_name (G_TYPE_FROM_INSTANCE (instance)),
3145 if (g_trap_instance_signals == instance)
3148 #endif /* G_ENABLE_DEBUG */
3150 TRACE(GOBJECT_SIGNAL_EMIT(node->signal_id, detail, instance, G_TYPE_FROM_INSTANCE (instance)));
3153 signal_id = node->signal_id;
3154 if (node->flags & G_SIGNAL_NO_RECURSE)
3156 Emission *node = emission_find (g_restart_emissions, signal_id, detail, instance);
3160 node->state = EMISSION_RESTART;
3162 return return_value_altered;
3165 accumulator = node->accumulator;
3169 g_value_init (&accu, node->return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE);
3170 return_accu = &accu;
3174 return_accu = emission_return;
3175 emission.instance = instance;
3176 emission.ihint.signal_id = node->signal_id;
3177 emission.ihint.detail = detail;
3178 emission.ihint.run_type = 0;
3180 emission.chain_type = G_TYPE_NONE;
3181 emission_push ((node->flags & G_SIGNAL_NO_RECURSE) ? &g_restart_emissions : &g_recursive_emissions, &emission);
3182 class_closure = signal_lookup_closure (node, instance);
3187 handler_unref_R (signal_id, instance, handler_list);
3188 max_sequential_handler_number = g_handler_sequential_number;
3189 hlist = handler_list_lookup (signal_id, instance);
3190 handler_list = hlist ? hlist->handlers : NULL;
3192 handler_ref (handler_list);
3194 emission.ihint.run_type = G_SIGNAL_RUN_FIRST;
3196 if ((node->flags & G_SIGNAL_RUN_FIRST) && class_closure)
3198 emission.state = EMISSION_RUN;
3200 emission.chain_type = G_TYPE_FROM_INSTANCE (instance);
3202 g_closure_invoke (class_closure,
3205 instance_and_params,
3207 if (!accumulate (&emission.ihint, emission_return, &accu, accumulator) &&
3208 emission.state == EMISSION_RUN)
3209 emission.state = EMISSION_STOP;
3211 emission.chain_type = G_TYPE_NONE;
3212 return_value_altered = TRUE;
3214 if (emission.state == EMISSION_STOP)
3216 else if (emission.state == EMISSION_RESTART)
3220 if (node->emission_hooks)
3222 gboolean need_destroy, was_in_call, may_recurse = TRUE;
3225 emission.state = EMISSION_HOOK;
3226 hook = g_hook_first_valid (node->emission_hooks, may_recurse);
3229 SignalHook *signal_hook = SIGNAL_HOOK (hook);
3231 if (!signal_hook->detail || signal_hook->detail == detail)
3233 GSignalEmissionHook hook_func = (GSignalEmissionHook) hook->func;
3235 was_in_call = G_HOOK_IN_CALL (hook);
3236 hook->flags |= G_HOOK_FLAG_IN_CALL;
3238 need_destroy = !hook_func (&emission.ihint, node->n_params + 1, instance_and_params, hook->data);
3241 hook->flags &= ~G_HOOK_FLAG_IN_CALL;
3243 g_hook_destroy_link (node->emission_hooks, hook);
3245 hook = g_hook_next_valid (node->emission_hooks, hook, may_recurse);
3248 if (emission.state == EMISSION_RESTART)
3254 Handler *handler = handler_list;
3256 emission.state = EMISSION_RUN;
3257 handler_ref (handler);
3264 handler_unref_R (signal_id, instance, handler_list);
3265 handler_list = handler;
3268 else if (!handler->block_count && (!handler->detail || handler->detail == detail) &&
3269 handler->sequential_number < max_sequential_handler_number)
3272 g_closure_invoke (handler->closure,
3275 instance_and_params,
3277 if (!accumulate (&emission.ihint, emission_return, &accu, accumulator) &&
3278 emission.state == EMISSION_RUN)
3279 emission.state = EMISSION_STOP;
3281 return_value_altered = TRUE;
3283 tmp = emission.state == EMISSION_RUN ? handler->next : NULL;
3286 tmp = handler->next;
3290 handler_unref_R (signal_id, instance, handler_list);
3291 handler_list = handler;
3296 if (emission.state == EMISSION_STOP)
3298 else if (emission.state == EMISSION_RESTART)
3302 emission.ihint.run_type = G_SIGNAL_RUN_LAST;
3304 if ((node->flags & G_SIGNAL_RUN_LAST) && class_closure)
3306 emission.state = EMISSION_RUN;
3308 emission.chain_type = G_TYPE_FROM_INSTANCE (instance);
3310 g_closure_invoke (class_closure,
3313 instance_and_params,
3315 if (!accumulate (&emission.ihint, emission_return, &accu, accumulator) &&
3316 emission.state == EMISSION_RUN)
3317 emission.state = EMISSION_STOP;
3319 emission.chain_type = G_TYPE_NONE;
3320 return_value_altered = TRUE;
3322 if (emission.state == EMISSION_STOP)
3324 else if (emission.state == EMISSION_RESTART)
3330 Handler *handler = handler_list;
3332 emission.state = EMISSION_RUN;
3333 handler_ref (handler);
3338 if (handler->after && !handler->block_count && (!handler->detail || handler->detail == detail) &&
3339 handler->sequential_number < max_sequential_handler_number)
3342 g_closure_invoke (handler->closure,
3345 instance_and_params,
3347 if (!accumulate (&emission.ihint, emission_return, &accu, accumulator) &&
3348 emission.state == EMISSION_RUN)
3349 emission.state = EMISSION_STOP;
3351 return_value_altered = TRUE;
3353 tmp = emission.state == EMISSION_RUN ? handler->next : NULL;
3356 tmp = handler->next;
3360 handler_unref_R (signal_id, instance, handler);
3365 if (emission.state == EMISSION_STOP)
3367 else if (emission.state == EMISSION_RESTART)
3373 emission.ihint.run_type = G_SIGNAL_RUN_CLEANUP;
3375 if ((node->flags & G_SIGNAL_RUN_CLEANUP) && class_closure)
3377 gboolean need_unset = FALSE;
3379 emission.state = EMISSION_STOP;
3381 emission.chain_type = G_TYPE_FROM_INSTANCE (instance);
3383 if (node->return_type != G_TYPE_NONE && !accumulator)
3385 g_value_init (&accu, node->return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE);
3388 g_closure_invoke (class_closure,
3389 node->return_type != G_TYPE_NONE ? &accu : NULL,
3391 instance_and_params,
3394 g_value_unset (&accu);
3396 emission.chain_type = G_TYPE_NONE;
3398 if (emission.state == EMISSION_RESTART)
3403 handler_unref_R (signal_id, instance, handler_list);
3405 emission_pop ((node->flags & G_SIGNAL_NO_RECURSE) ? &g_restart_emissions : &g_recursive_emissions, &emission);
3408 g_value_unset (&accu);
3410 TRACE(GOBJECT_SIGNAL_EMIT_END(node->signal_id, detail, instance, G_TYPE_FROM_INSTANCE (instance)));
3412 return return_value_altered;
3416 type_debug_name (GType type)
3420 const char *name = g_type_name (type & ~G_SIGNAL_TYPE_STATIC_SCOPE);
3421 return name ? name : "<unknown>";
3428 * g_signal_accumulator_true_handled:
3429 * @ihint: standard #GSignalAccumulator parameter
3430 * @return_accu: standard #GSignalAccumulator parameter
3431 * @handler_return: standard #GSignalAccumulator parameter
3432 * @dummy: standard #GSignalAccumulator parameter
3434 * A predefined #GSignalAccumulator for signals that return a
3435 * boolean values. The behavior that this accumulator gives is
3436 * that a return of %TRUE stops the signal emission: no further
3437 * callbacks will be invoked, while a return of %FALSE allows
3438 * the emission to continue. The idea here is that a %TRUE return
3439 * indicates that the callback <emphasis>handled</emphasis> the signal,
3440 * and no further handling is needed.
3444 * Returns: standard #GSignalAccumulator result
3447 g_signal_accumulator_true_handled (GSignalInvocationHint *ihint,
3448 GValue *return_accu,
3449 const GValue *handler_return,
3452 gboolean continue_emission;
3453 gboolean signal_handled;
3455 signal_handled = g_value_get_boolean (handler_return);
3456 g_value_set_boolean (return_accu, signal_handled);
3457 continue_emission = !signal_handled;
3459 return continue_emission;
3463 * g_signal_accumulator_first_wins:
3464 * @ihint: standard #GSignalAccumulator parameter
3465 * @return_accu: standard #GSignalAccumulator parameter
3466 * @handler_return: standard #GSignalAccumulator parameter
3467 * @dummy: standard #GSignalAccumulator parameter
3469 * A predefined #GSignalAccumulator for signals intended to be used as a
3470 * hook for application code to provide a particular value. Usually
3471 * only one such value is desired and multiple handlers for the same
3472 * signal don't make much sense (except for the case of the default
3473 * handler defined in the class structure, in which case you will
3474 * usually want the signal connection to override the class handler).
3476 * This accumulator will use the return value from the first signal
3477 * handler that is run as the return value for the signal and not run
3478 * any further handlers (ie: the first handler "wins").
3480 * Returns: standard #GSignalAccumulator result
3485 g_signal_accumulator_first_wins (GSignalInvocationHint *ihint,
3486 GValue *return_accu,
3487 const GValue *handler_return,
3490 g_value_copy (handler_return, return_accu);