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);
183 static void node_check_deprecated (const SignalNode *node);
186 /* --- structures --- */
189 GSignalAccumulator func;
197 #define SIGNAL_HOOK(hook) ((SignalHook*) (hook))
201 /* permanent portion */
207 /* reinitializable portion */
208 guint test_class_offset : 12;
211 GType *param_types; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
212 GType return_type; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
213 GBSearchArray *class_closure_bsa;
214 SignalAccumulator *accumulator;
215 GSignalCMarshaller c_marshaller;
216 GHookList *emission_hooks;
218 #define MAX_TEST_CLASS_OFFSET (4096) /* 2^12, 12 bits for test_class_offset */
219 #define TEST_CLASS_MAGIC (1) /* indicates NULL class closure, candidate for NOP optimization */
232 GSignalInvocationHint ihint;
241 Handler *tail_before; /* normal signal handlers are appended here */
242 Handler *tail_after; /* CONNECT_AFTER handlers are appended here */
247 gulong sequential_number;
252 guint block_count : 16;
253 #define HANDLER_MAX_BLOCK_COUNT (1 << 16)
266 GType instance_type; /* 0 for default closure */
271 /* --- variables --- */
272 static GBSearchArray *g_signal_key_bsa = NULL;
273 static const GBSearchConfig g_signal_key_bconfig = {
276 G_BSEARCH_ARRAY_ALIGN_POWER2,
278 static GBSearchConfig g_signal_hlbsa_bconfig = {
279 sizeof (HandlerList),
283 static GBSearchConfig g_class_closure_bconfig = {
284 sizeof (ClassClosure),
288 static GHashTable *g_handler_list_bsa_ht = NULL;
289 static Emission *g_recursive_emissions = NULL;
290 static Emission *g_restart_emissions = NULL;
291 static gulong g_handler_sequential_number = 1;
292 G_LOCK_DEFINE_STATIC (g_signal_mutex);
293 #define SIGNAL_LOCK() G_LOCK (g_signal_mutex)
294 #define SIGNAL_UNLOCK() G_UNLOCK (g_signal_mutex)
297 /* --- signal nodes --- */
298 static guint g_n_signal_nodes = 0;
299 static SignalNode **g_signal_nodes = NULL;
301 static inline SignalNode*
302 LOOKUP_SIGNAL_NODE (register guint signal_id)
304 if (signal_id < g_n_signal_nodes)
305 return g_signal_nodes[signal_id];
311 /* --- functions --- */
313 signal_id_lookup (GQuark quark,
316 GType *ifaces, type = itype;
322 /* try looking up signals for this type and its ancestors */
325 SignalKey *signal_key;
328 signal_key = g_bsearch_array_lookup (g_signal_key_bsa, &g_signal_key_bconfig, &key);
331 return signal_key->signal_id;
333 type = g_type_parent (type);
337 /* no luck, try interfaces it exports */
338 ifaces = g_type_interfaces (itype, &n_ifaces);
341 SignalKey *signal_key;
343 key.itype = ifaces[n_ifaces];
344 signal_key = g_bsearch_array_lookup (g_signal_key_bsa, &g_signal_key_bconfig, &key);
349 return signal_key->signal_id;
358 class_closures_cmp (gconstpointer node1,
361 const ClassClosure *c1 = node1, *c2 = node2;
363 return G_BSEARCH_ARRAY_CMP (c1->instance_type, c2->instance_type);
367 handler_lists_cmp (gconstpointer node1,
370 const HandlerList *hlist1 = node1, *hlist2 = node2;
372 return G_BSEARCH_ARRAY_CMP (hlist1->signal_id, hlist2->signal_id);
375 static inline HandlerList*
376 handler_list_ensure (guint signal_id,
379 GBSearchArray *hlbsa = g_hash_table_lookup (g_handler_list_bsa_ht, instance);
382 key.signal_id = signal_id;
384 key.tail_before = NULL;
385 key.tail_after = NULL;
388 hlbsa = g_bsearch_array_create (&g_signal_hlbsa_bconfig);
389 hlbsa = g_bsearch_array_insert (hlbsa, &g_signal_hlbsa_bconfig, &key);
390 g_hash_table_insert (g_handler_list_bsa_ht, instance, hlbsa);
394 GBSearchArray *o = hlbsa;
396 hlbsa = g_bsearch_array_insert (o, &g_signal_hlbsa_bconfig, &key);
398 g_hash_table_insert (g_handler_list_bsa_ht, instance, hlbsa);
400 return g_bsearch_array_lookup (hlbsa, &g_signal_hlbsa_bconfig, &key);
403 static inline HandlerList*
404 handler_list_lookup (guint signal_id,
407 GBSearchArray *hlbsa = g_hash_table_lookup (g_handler_list_bsa_ht, instance);
410 key.signal_id = signal_id;
412 return hlbsa ? g_bsearch_array_lookup (hlbsa, &g_signal_hlbsa_bconfig, &key) : NULL;
416 handler_lookup (gpointer instance,
420 GBSearchArray *hlbsa = g_hash_table_lookup (g_handler_list_bsa_ht, instance);
426 for (i = 0; i < hlbsa->n_nodes; i++)
428 HandlerList *hlist = g_bsearch_array_get_nth (hlbsa, &g_signal_hlbsa_bconfig, i);
431 for (handler = hlist->handlers; handler; handler = handler->next)
432 if (handler->sequential_number == handler_id)
435 *signal_id_p = hlist->signal_id;
445 static inline HandlerMatch*
446 handler_match_prepend (HandlerMatch *list,
452 node = g_slice_new (HandlerMatch);
453 node->handler = handler;
455 node->signal_id = signal_id;
456 handler_ref (handler);
460 static inline HandlerMatch*
461 handler_match_free1_R (HandlerMatch *node,
464 HandlerMatch *next = node->next;
466 handler_unref_R (node->signal_id, instance, node->handler);
467 g_slice_free (HandlerMatch, node);
473 handlers_find (gpointer instance,
474 GSignalMatchType mask,
480 gboolean one_and_only)
482 HandlerMatch *mlist = NULL;
484 if (mask & G_SIGNAL_MATCH_ID)
486 HandlerList *hlist = handler_list_lookup (signal_id, instance);
488 SignalNode *node = NULL;
490 if (mask & G_SIGNAL_MATCH_FUNC)
492 node = LOOKUP_SIGNAL_NODE (signal_id);
493 if (!node || !node->c_marshaller)
498 for (handler = hlist ? hlist->handlers : NULL; handler; handler = handler->next)
499 if (handler->sequential_number &&
500 ((mask & G_SIGNAL_MATCH_DETAIL) || handler->detail == detail) &&
501 ((mask & G_SIGNAL_MATCH_CLOSURE) || handler->closure == closure) &&
502 ((mask & G_SIGNAL_MATCH_DATA) || handler->closure->data == data) &&
503 ((mask & G_SIGNAL_MATCH_UNBLOCKED) || handler->block_count == 0) &&
504 ((mask & G_SIGNAL_MATCH_FUNC) || (handler->closure->marshal == node->c_marshaller &&
505 handler->closure->meta_marshal == 0 &&
506 ((GCClosure*) handler->closure)->callback == func)))
508 mlist = handler_match_prepend (mlist, handler, signal_id);
515 GBSearchArray *hlbsa = g_hash_table_lookup (g_handler_list_bsa_ht, instance);
522 for (i = 0; i < hlbsa->n_nodes; i++)
524 HandlerList *hlist = g_bsearch_array_get_nth (hlbsa, &g_signal_hlbsa_bconfig, i);
525 SignalNode *node = NULL;
528 if (!(mask & G_SIGNAL_MATCH_FUNC))
530 node = LOOKUP_SIGNAL_NODE (hlist->signal_id);
531 if (!node->c_marshaller)
535 for (handler = hlist->handlers; handler; handler = handler->next)
536 if (handler->sequential_number &&
537 ((mask & G_SIGNAL_MATCH_DETAIL) || handler->detail == detail) &&
538 ((mask & G_SIGNAL_MATCH_CLOSURE) || handler->closure == closure) &&
539 ((mask & G_SIGNAL_MATCH_DATA) || handler->closure->data == data) &&
540 ((mask & G_SIGNAL_MATCH_UNBLOCKED) || handler->block_count == 0) &&
541 ((mask & G_SIGNAL_MATCH_FUNC) || (handler->closure->marshal == node->c_marshaller &&
542 handler->closure->meta_marshal == 0 &&
543 ((GCClosure*) handler->closure)->callback == func)))
545 mlist = handler_match_prepend (mlist, handler, hlist->signal_id);
556 static inline Handler*
557 handler_new (gboolean after)
559 Handler *handler = g_slice_new (Handler);
560 #ifndef G_DISABLE_CHECKS
561 if (g_handler_sequential_number < 1)
562 g_error (G_STRLOC ": handler id overflow, %s", REPORT_BUG);
565 handler->sequential_number = g_handler_sequential_number++;
566 handler->prev = NULL;
567 handler->next = NULL;
569 handler->ref_count = 1;
570 handler->block_count = 0;
571 handler->after = after != FALSE;
572 handler->closure = NULL;
578 handler_ref (Handler *handler)
580 g_return_if_fail (handler->ref_count > 0);
582 g_atomic_int_inc ((int *)&handler->ref_count);
586 handler_unref_R (guint signal_id,
592 g_return_if_fail (handler->ref_count > 0);
594 is_zero = g_atomic_int_dec_and_test ((int *)&handler->ref_count);
596 if (G_UNLIKELY (is_zero))
598 HandlerList *hlist = NULL;
601 handler->next->prev = handler->prev;
602 if (handler->prev) /* watch out for g_signal_handlers_destroy()! */
603 handler->prev->next = handler->next;
606 hlist = handler_list_lookup (signal_id, instance);
607 hlist->handlers = handler->next;
612 /* check if we are removing the handler pointed to by tail_before */
613 if (!handler->after && (!handler->next || handler->next->after))
616 hlist = handler_list_lookup (signal_id, instance);
619 g_assert (hlist->tail_before == handler); /* paranoid */
620 hlist->tail_before = handler->prev;
624 /* check if we are removing the handler pointed to by tail_after */
628 hlist = handler_list_lookup (signal_id, instance);
631 g_assert (hlist->tail_after == handler); /* paranoid */
632 hlist->tail_after = handler->prev;
638 g_closure_unref (handler->closure);
640 g_slice_free (Handler, handler);
645 handler_insert (guint signal_id,
651 g_assert (handler->prev == NULL && handler->next == NULL); /* paranoid */
653 hlist = handler_list_ensure (signal_id, instance);
654 if (!hlist->handlers)
656 hlist->handlers = handler;
658 hlist->tail_before = handler;
660 else if (handler->after)
662 handler->prev = hlist->tail_after;
663 hlist->tail_after->next = handler;
667 if (hlist->tail_before)
669 handler->next = hlist->tail_before->next;
671 handler->next->prev = handler;
672 handler->prev = hlist->tail_before;
673 hlist->tail_before->next = handler;
675 else /* insert !after handler into a list of only after handlers */
677 handler->next = hlist->handlers;
679 handler->next->prev = handler;
680 hlist->handlers = handler;
682 hlist->tail_before = handler;
686 hlist->tail_after = handler;
690 emission_push (Emission **emission_list_p,
693 emission->next = *emission_list_p;
694 *emission_list_p = emission;
698 emission_pop (Emission **emission_list_p,
701 Emission *node, *last = NULL;
703 for (node = *emission_list_p; node; last = node, node = last->next)
704 if (node == emission)
707 last->next = node->next;
709 *emission_list_p = node->next;
712 g_assert_not_reached ();
715 static inline Emission*
716 emission_find (Emission *emission_list,
723 for (emission = emission_list; emission; emission = emission->next)
724 if (emission->instance == instance &&
725 emission->ihint.signal_id == signal_id &&
726 emission->ihint.detail == detail)
731 static inline Emission*
732 emission_find_innermost (gpointer instance)
734 Emission *emission, *s = NULL, *c = NULL;
736 for (emission = g_restart_emissions; emission; emission = emission->next)
737 if (emission->instance == instance)
742 for (emission = g_recursive_emissions; emission; emission = emission->next)
743 if (emission->instance == instance)
753 return G_HAVE_GROWING_STACK ? MAX (c, s) : MIN (c, s);
757 signal_key_cmp (gconstpointer node1,
760 const SignalKey *key1 = node1, *key2 = node2;
762 if (key1->itype == key2->itype)
763 return G_BSEARCH_ARRAY_CMP (key1->quark, key2->quark);
765 return G_BSEARCH_ARRAY_CMP (key1->itype, key2->itype);
769 _g_signal_init (void)
772 if (!g_n_signal_nodes)
774 /* setup handler list binary searchable array hash table (in german, that'd be one word ;) */
775 g_handler_list_bsa_ht = g_hash_table_new (g_direct_hash, NULL);
776 g_signal_key_bsa = g_bsearch_array_create (&g_signal_key_bconfig);
778 /* invalid (0) signal_id */
779 g_n_signal_nodes = 1;
780 g_signal_nodes = g_renew (SignalNode*, g_signal_nodes, g_n_signal_nodes);
781 g_signal_nodes[0] = NULL;
787 _g_signals_destroy (GType itype)
792 for (i = 1; i < g_n_signal_nodes; i++)
794 SignalNode *node = g_signal_nodes[i];
796 if (node->itype == itype)
799 g_warning (G_STRLOC ": signal \"%s\" of type `%s' already destroyed",
801 type_debug_name (node->itype));
803 signal_destroy_R (node);
810 * g_signal_stop_emission:
811 * @instance: the object whose signal handlers you wish to stop.
812 * @signal_id: the signal identifier, as returned by g_signal_lookup().
813 * @detail: the detail which the signal was emitted with.
815 * Stops a signal's current emission.
817 * This will prevent the default method from running, if the signal was
818 * %G_SIGNAL_RUN_LAST and you connected normally (i.e. without the "after"
821 * Prints a warning if used on a signal which isn't being emitted.
824 g_signal_stop_emission (gpointer instance,
830 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
831 g_return_if_fail (signal_id > 0);
834 node = LOOKUP_SIGNAL_NODE (signal_id);
835 if (node && detail && !(node->flags & G_SIGNAL_DETAILED))
837 g_warning ("%s: signal id `%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
841 if (node && g_type_is_a (G_TYPE_FROM_INSTANCE (instance), node->itype))
843 Emission *emission_list = node->flags & G_SIGNAL_NO_RECURSE ? g_restart_emissions : g_recursive_emissions;
844 Emission *emission = emission_find (emission_list, signal_id, detail, instance);
848 if (emission->state == EMISSION_HOOK)
849 g_warning (G_STRLOC ": emission of signal \"%s\" for instance `%p' cannot be stopped from emission hook",
850 node->name, instance);
851 else if (emission->state == EMISSION_RUN)
852 emission->state = EMISSION_STOP;
855 g_warning (G_STRLOC ": no emission of signal \"%s\" to stop for instance `%p'",
856 node->name, instance);
859 g_warning ("%s: signal id `%u' is invalid for instance `%p'", G_STRLOC, signal_id, instance);
864 signal_finalize_hook (GHookList *hook_list,
867 GDestroyNotify destroy = hook->destroy;
871 hook->destroy = NULL;
873 destroy (hook->data);
879 * g_signal_add_emission_hook:
880 * @signal_id: the signal identifier, as returned by g_signal_lookup().
881 * @detail: the detail on which to call the hook.
882 * @hook_func: a #GSignalEmissionHook function.
883 * @hook_data: user data for @hook_func.
884 * @data_destroy: a #GDestroyNotify for @hook_data.
886 * Adds an emission hook for a signal, which will get called for any emission
887 * of that signal, independent of the instance. This is possible only
888 * for signals which don't have #G_SIGNAL_NO_HOOKS flag set.
890 * Returns: the hook id, for later use with g_signal_remove_emission_hook().
893 g_signal_add_emission_hook (guint signal_id,
895 GSignalEmissionHook hook_func,
897 GDestroyNotify data_destroy)
899 static gulong seq_hook_id = 1;
902 SignalHook *signal_hook;
904 g_return_val_if_fail (signal_id > 0, 0);
905 g_return_val_if_fail (hook_func != NULL, 0);
908 node = LOOKUP_SIGNAL_NODE (signal_id);
909 if (!node || node->destroyed)
911 g_warning ("%s: invalid signal id `%u'", G_STRLOC, signal_id);
915 if (node->flags & G_SIGNAL_NO_HOOKS)
917 g_warning ("%s: signal id `%u' does not support emission hooks (G_SIGNAL_NO_HOOKS flag set)", G_STRLOC, signal_id);
921 if (detail && !(node->flags & G_SIGNAL_DETAILED))
923 g_warning ("%s: signal id `%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
927 if (!node->emission_hooks)
929 node->emission_hooks = g_new (GHookList, 1);
930 g_hook_list_init (node->emission_hooks, sizeof (SignalHook));
931 node->emission_hooks->finalize_hook = signal_finalize_hook;
934 node_check_deprecated (node);
936 hook = g_hook_alloc (node->emission_hooks);
937 hook->data = hook_data;
938 hook->func = (gpointer) hook_func;
939 hook->destroy = data_destroy;
940 signal_hook = SIGNAL_HOOK (hook);
941 signal_hook->detail = detail;
942 node->emission_hooks->seq_id = seq_hook_id;
943 g_hook_append (node->emission_hooks, hook);
944 seq_hook_id = node->emission_hooks->seq_id;
947 return hook->hook_id;
951 * g_signal_remove_emission_hook:
952 * @signal_id: the id of the signal
953 * @hook_id: the id of the emission hook, as returned by
954 * g_signal_add_emission_hook()
956 * Deletes an emission hook.
959 g_signal_remove_emission_hook (guint signal_id,
964 g_return_if_fail (signal_id > 0);
965 g_return_if_fail (hook_id > 0);
968 node = LOOKUP_SIGNAL_NODE (signal_id);
969 if (!node || node->destroyed)
970 g_warning ("%s: invalid signal id `%u'", G_STRLOC, signal_id);
971 else if (!node->emission_hooks || !g_hook_destroy (node->emission_hooks, hook_id))
972 g_warning ("%s: signal \"%s\" had no hook (%lu) to remove", G_STRLOC, node->name, hook_id);
977 signal_parse_name (const gchar *name,
980 gboolean force_quark)
982 const gchar *colon = strchr (name, ':');
987 signal_id = signal_id_lookup (g_quark_try_string (name), itype);
988 if (signal_id && detail_p)
991 else if (colon[1] == ':')
994 guint l = colon - name;
998 memcpy (buffer, name, l);
1000 signal_id = signal_id_lookup (g_quark_try_string (buffer), itype);
1004 gchar *signal = g_new (gchar, l + 1);
1006 memcpy (signal, name, l);
1008 signal_id = signal_id_lookup (g_quark_try_string (signal), itype);
1012 if (signal_id && detail_p)
1013 *detail_p = colon[2] ? (force_quark ? g_quark_from_string : g_quark_try_string) (colon + 2) : 0;
1021 * g_signal_parse_name:
1022 * @detailed_signal: a string of the form "signal-name::detail".
1023 * @itype: The interface/instance type that introduced "signal-name".
1024 * @signal_id_p: (out): Location to store the signal id.
1025 * @detail_p: (out): Location to store the detail quark.
1026 * @force_detail_quark: %TRUE forces creation of a #GQuark for the detail.
1028 * Internal function to parse a signal name into its @signal_id
1029 * and @detail quark.
1031 * Returns: Whether the signal name could successfully be parsed and @signal_id_p and @detail_p contain valid return values.
1034 g_signal_parse_name (const gchar *detailed_signal,
1038 gboolean force_detail_quark)
1044 g_return_val_if_fail (detailed_signal != NULL, FALSE);
1045 g_return_val_if_fail (G_TYPE_IS_INSTANTIATABLE (itype) || G_TYPE_IS_INTERFACE (itype), FALSE);
1048 signal_id = signal_parse_name (detailed_signal, itype, &detail, force_detail_quark);
1051 node = signal_id ? LOOKUP_SIGNAL_NODE (signal_id) : NULL;
1052 if (!node || node->destroyed ||
1053 (detail && !(node->flags & G_SIGNAL_DETAILED)))
1057 *signal_id_p = signal_id;
1065 * g_signal_stop_emission_by_name:
1066 * @instance: the object whose signal handlers you wish to stop.
1067 * @detailed_signal: a string of the form "signal-name::detail".
1069 * Stops a signal's current emission.
1071 * This is just like g_signal_stop_emission() except it will look up the
1072 * signal id for you.
1075 g_signal_stop_emission_by_name (gpointer instance,
1076 const gchar *detailed_signal)
1082 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
1083 g_return_if_fail (detailed_signal != NULL);
1086 itype = G_TYPE_FROM_INSTANCE (instance);
1087 signal_id = signal_parse_name (detailed_signal, itype, &detail, TRUE);
1090 SignalNode *node = LOOKUP_SIGNAL_NODE (signal_id);
1092 if (detail && !(node->flags & G_SIGNAL_DETAILED))
1093 g_warning ("%s: signal `%s' does not support details", G_STRLOC, detailed_signal);
1094 else if (!g_type_is_a (itype, node->itype))
1095 g_warning ("%s: signal `%s' is invalid for instance `%p'", G_STRLOC, detailed_signal, instance);
1098 Emission *emission_list = node->flags & G_SIGNAL_NO_RECURSE ? g_restart_emissions : g_recursive_emissions;
1099 Emission *emission = emission_find (emission_list, signal_id, detail, instance);
1103 if (emission->state == EMISSION_HOOK)
1104 g_warning (G_STRLOC ": emission of signal \"%s\" for instance `%p' cannot be stopped from emission hook",
1105 node->name, instance);
1106 else if (emission->state == EMISSION_RUN)
1107 emission->state = EMISSION_STOP;
1110 g_warning (G_STRLOC ": no emission of signal \"%s\" to stop for instance `%p'",
1111 node->name, instance);
1115 g_warning ("%s: signal `%s' is invalid for instance `%p'", G_STRLOC, detailed_signal, instance);
1121 * @name: the signal's name.
1122 * @itype: the type that the signal operates on.
1124 * Given the name of the signal and the type of object it connects to, gets
1125 * the signal's identifying integer. Emitting the signal by number is
1126 * somewhat faster than using the name each time.
1128 * Also tries the ancestors of the given type.
1130 * See g_signal_new() for details on allowed signal names.
1132 * Returns: the signal's identifying number, or 0 if no signal was found.
1135 g_signal_lookup (const gchar *name,
1139 g_return_val_if_fail (name != NULL, 0);
1140 g_return_val_if_fail (G_TYPE_IS_INSTANTIATABLE (itype) || G_TYPE_IS_INTERFACE (itype), 0);
1143 signal_id = signal_id_lookup (g_quark_try_string (name), itype);
1147 /* give elaborate warnings */
1148 if (!g_type_name (itype))
1149 g_warning (G_STRLOC ": unable to lookup signal \"%s\" for invalid type id `%"G_GSIZE_FORMAT"'",
1151 else if (!G_TYPE_IS_INSTANTIATABLE (itype))
1152 g_warning (G_STRLOC ": unable to lookup signal \"%s\" for non instantiatable type `%s'",
1153 name, g_type_name (itype));
1154 else if (!g_type_class_peek (itype))
1155 g_warning (G_STRLOC ": unable to lookup signal \"%s\" of unloaded type `%s'",
1156 name, g_type_name (itype));
1163 * g_signal_list_ids:
1164 * @itype: Instance or interface type.
1165 * @n_ids: Location to store the number of signal ids for @itype.
1167 * Lists the signals by id that a certain instance or interface type
1168 * created. Further information about the signals can be acquired through
1171 * Returns: (array length=n_ids): Newly allocated array of signal IDs.
1174 g_signal_list_ids (GType itype,
1182 g_return_val_if_fail (G_TYPE_IS_INSTANTIATABLE (itype) || G_TYPE_IS_INTERFACE (itype), NULL);
1183 g_return_val_if_fail (n_ids != NULL, NULL);
1186 keys = g_bsearch_array_get_nth (g_signal_key_bsa, &g_signal_key_bconfig, 0);
1187 n_nodes = g_bsearch_array_get_n_nodes (g_signal_key_bsa);
1188 result = g_array_new (FALSE, FALSE, sizeof (guint));
1190 for (i = 0; i < n_nodes; i++)
1191 if (keys[i].itype == itype)
1193 const gchar *name = g_quark_to_string (keys[i].quark);
1195 /* Signal names with "_" in them are aliases to the same
1196 * name with "-" instead of "_".
1198 if (!strchr (name, '_'))
1199 g_array_append_val (result, keys[i].signal_id);
1201 *n_ids = result->len;
1205 /* give elaborate warnings */
1206 if (!g_type_name (itype))
1207 g_warning (G_STRLOC ": unable to list signals for invalid type id `%"G_GSIZE_FORMAT"'",
1209 else if (!G_TYPE_IS_INSTANTIATABLE (itype) && !G_TYPE_IS_INTERFACE (itype))
1210 g_warning (G_STRLOC ": unable to list signals of non instantiatable type `%s'",
1211 g_type_name (itype));
1212 else if (!g_type_class_peek (itype) && !G_TYPE_IS_INTERFACE (itype))
1213 g_warning (G_STRLOC ": unable to list signals of unloaded type `%s'",
1214 g_type_name (itype));
1217 return (guint*) g_array_free (result, FALSE);
1222 * @signal_id: the signal's identifying number.
1224 * Given the signal's identifier, finds its name.
1226 * Two different signals may have the same name, if they have differing types.
1228 * Returns: the signal name, or %NULL if the signal number was invalid.
1231 g_signal_name (guint signal_id)
1237 node = LOOKUP_SIGNAL_NODE (signal_id);
1238 name = node ? node->name : NULL;
1241 return (char*) name;
1246 * @signal_id: The signal id of the signal to query information for.
1247 * @query: (out caller-allocates): A user provided structure that is
1248 * filled in with constant values upon success.
1250 * Queries the signal system for in-depth information about a
1251 * specific signal. This function will fill in a user-provided
1252 * structure to hold signal-specific information. If an invalid
1253 * signal id is passed in, the @signal_id member of the #GSignalQuery
1254 * is 0. All members filled into the #GSignalQuery structure should
1255 * be considered constant and have to be left untouched.
1258 g_signal_query (guint signal_id,
1259 GSignalQuery *query)
1263 g_return_if_fail (query != NULL);
1266 node = LOOKUP_SIGNAL_NODE (signal_id);
1267 if (!node || node->destroyed)
1268 query->signal_id = 0;
1271 query->signal_id = node->signal_id;
1272 query->signal_name = node->name;
1273 query->itype = node->itype;
1274 query->signal_flags = node->flags;
1275 query->return_type = node->return_type;
1276 query->n_params = node->n_params;
1277 query->param_types = node->param_types;
1284 * @signal_name: the name for the signal
1285 * @itype: the type this signal pertains to. It will also pertain to
1286 * types which are derived from this type.
1287 * @signal_flags: a combination of #GSignalFlags specifying detail of when
1288 * the default handler is to be invoked. You should at least specify
1289 * %G_SIGNAL_RUN_FIRST or %G_SIGNAL_RUN_LAST.
1290 * @class_offset: The offset of the function pointer in the class structure
1291 * for this type. Used to invoke a class method generically. Pass 0 to
1292 * not associate a class method slot with this signal.
1293 * @accumulator: the accumulator for this signal; may be %NULL.
1294 * @accu_data: user data for the @accumulator.
1295 * @c_marshaller: (allow-none): the function to translate arrays of parameter
1296 * values to signal emissions into C language callback invocations or %NULL.
1297 * @return_type: the type of return value, or #G_TYPE_NONE for a signal
1298 * without a return value.
1299 * @n_params: the number of parameter types to follow.
1300 * @...: a list of types, one for each parameter.
1302 * Creates a new signal. (This is usually done in the class initializer.)
1304 * A signal name consists of segments consisting of ASCII letters and
1305 * digits, separated by either the '-' or '_' character. The first
1306 * character of a signal name must be a letter. Names which violate these
1307 * rules lead to undefined behaviour of the GSignal system.
1309 * When registering a signal and looking up a signal, either separator can
1310 * be used, but they cannot be mixed.
1312 * If 0 is used for @class_offset subclasses cannot override the class handler
1313 * in their <code>class_init</code> method by doing
1314 * <code>super_class->signal_handler = my_signal_handler</code>. Instead they
1315 * will have to use g_signal_override_class_handler().
1317 * If c_marshaller is %NULL, g_cclosure_marshal_generic() will be used as
1318 * the marshaller for this signal.
1320 * Returns: the signal id
1323 g_signal_new (const gchar *signal_name,
1325 GSignalFlags signal_flags,
1327 GSignalAccumulator accumulator,
1329 GSignalCMarshaller c_marshaller,
1337 g_return_val_if_fail (signal_name != NULL, 0);
1339 va_start (args, n_params);
1341 signal_id = g_signal_new_valist (signal_name, itype, signal_flags,
1342 class_offset ? g_signal_type_cclosure_new (itype, class_offset) : NULL,
1343 accumulator, accu_data, c_marshaller,
1344 return_type, n_params, args);
1348 /* optimize NOP emissions with NULL class handlers */
1349 if (signal_id && G_TYPE_IS_INSTANTIATABLE (itype) && return_type == G_TYPE_NONE &&
1350 class_offset && class_offset < MAX_TEST_CLASS_OFFSET &&
1351 ~signal_flags & G_SIGNAL_MUST_COLLECT)
1356 node = LOOKUP_SIGNAL_NODE (signal_id);
1357 node->test_class_offset = class_offset;
1365 * g_signal_new_class_handler:
1366 * @signal_name: the name for the signal
1367 * @itype: the type this signal pertains to. It will also pertain to
1368 * types which are derived from this type.
1369 * @signal_flags: a combination of #GSignalFlags specifying detail of when
1370 * the default handler is to be invoked. You should at least specify
1371 * %G_SIGNAL_RUN_FIRST or %G_SIGNAL_RUN_LAST.
1372 * @class_handler: a #GCallback which acts as class implementation of
1373 * this signal. Used to invoke a class method generically. Pass %NULL to
1374 * not associate a class method with this signal.
1375 * @accumulator: the accumulator for this signal; may be %NULL.
1376 * @accu_data: user data for the @accumulator.
1377 * @c_marshaller: (allow-none): the function to translate arrays of parameter
1378 * values to signal emissions into C language callback invocations or %NULL.
1379 * @return_type: the type of return value, or #G_TYPE_NONE for a signal
1380 * without a return value.
1381 * @n_params: the number of parameter types to follow.
1382 * @...: a list of types, one for each parameter.
1384 * Creates a new signal. (This is usually done in the class initializer.)
1386 * This is a variant of g_signal_new() that takes a C callback instead
1387 * off a class offset for the signal's class handler. This function
1388 * doesn't need a function pointer exposed in the class structure of
1389 * an object definition, instead the function pointer is passed
1390 * directly and can be overriden by derived classes with
1391 * g_signal_override_class_closure() or
1392 * g_signal_override_class_handler()and chained to with
1393 * g_signal_chain_from_overridden() or
1394 * g_signal_chain_from_overridden_handler().
1396 * See g_signal_new() for information about signal names.
1398 * If c_marshaller is %NULL @g_cclosure_marshal_generic will be used as
1399 * the marshaller for this signal.
1401 * Returns: the signal id
1406 g_signal_new_class_handler (const gchar *signal_name,
1408 GSignalFlags signal_flags,
1409 GCallback class_handler,
1410 GSignalAccumulator accumulator,
1412 GSignalCMarshaller c_marshaller,
1420 g_return_val_if_fail (signal_name != NULL, 0);
1422 va_start (args, n_params);
1424 signal_id = g_signal_new_valist (signal_name, itype, signal_flags,
1425 class_handler ? g_cclosure_new (class_handler, NULL, NULL) : NULL,
1426 accumulator, accu_data, c_marshaller,
1427 return_type, n_params, args);
1434 static inline ClassClosure*
1435 signal_find_class_closure (SignalNode *node,
1438 GBSearchArray *bsa = node->class_closure_bsa;
1445 /* cc->instance_type is 0 for default closure */
1447 key.instance_type = itype;
1448 cc = g_bsearch_array_lookup (bsa, &g_class_closure_bconfig, &key);
1449 while (!cc && key.instance_type)
1451 key.instance_type = g_type_parent (key.instance_type);
1452 cc = g_bsearch_array_lookup (bsa, &g_class_closure_bconfig, &key);
1460 static inline GClosure*
1461 signal_lookup_closure (SignalNode *node,
1462 GTypeInstance *instance)
1466 if (node->class_closure_bsa && g_bsearch_array_get_n_nodes (node->class_closure_bsa) == 1)
1468 cc = g_bsearch_array_get_nth (node->class_closure_bsa, &g_class_closure_bconfig, 0);
1469 if (cc && cc->instance_type == 0) /* check for default closure */
1472 cc = signal_find_class_closure (node, G_TYPE_FROM_INSTANCE (instance));
1473 return cc ? cc->closure : NULL;
1477 signal_add_class_closure (SignalNode *node,
1483 /* can't optimize NOP emissions with overridden class closures */
1484 node->test_class_offset = 0;
1486 if (!node->class_closure_bsa)
1487 node->class_closure_bsa = g_bsearch_array_create (&g_class_closure_bconfig);
1488 key.instance_type = itype;
1489 key.closure = g_closure_ref (closure);
1490 node->class_closure_bsa = g_bsearch_array_insert (node->class_closure_bsa,
1491 &g_class_closure_bconfig,
1493 g_closure_sink (closure);
1494 if (node->c_marshaller && closure && G_CLOSURE_NEEDS_MARSHAL (closure))
1495 g_closure_set_marshal (closure, node->c_marshaller);
1500 * @signal_name: the name for the signal
1501 * @itype: the type this signal pertains to. It will also pertain to
1502 * types which are derived from this type
1503 * @signal_flags: a combination of #GSignalFlags specifying detail of when
1504 * the default handler is to be invoked. You should at least specify
1505 * %G_SIGNAL_RUN_FIRST or %G_SIGNAL_RUN_LAST
1506 * @class_closure: (allow-none): The closure to invoke on signal emission;
1508 * @accumulator: (allow-none): the accumulator for this signal; may be %NULL
1509 * @accu_data: user data for the @accumulator
1510 * @c_marshaller: (allow-none): the function to translate arrays of
1511 * parameter values to signal emissions into C language callback
1512 * invocations or %NULL
1513 * @return_type: the type of return value, or #G_TYPE_NONE for a signal
1514 * without a return value
1515 * @n_params: the length of @param_types
1516 * @param_types: (array length=n_params): an array of types, one for
1519 * Creates a new signal. (This is usually done in the class initializer.)
1521 * See g_signal_new() for details on allowed signal names.
1523 * If c_marshaller is %NULL @g_cclosure_marshal_generic will be used as
1524 * the marshaller for this signal.
1526 * Returns: the signal id
1529 g_signal_newv (const gchar *signal_name,
1531 GSignalFlags signal_flags,
1532 GClosure *class_closure,
1533 GSignalAccumulator accumulator,
1535 GSignalCMarshaller c_marshaller,
1544 g_return_val_if_fail (signal_name != NULL, 0);
1545 g_return_val_if_fail (G_TYPE_IS_INSTANTIATABLE (itype) || G_TYPE_IS_INTERFACE (itype), 0);
1547 g_return_val_if_fail (param_types != NULL, 0);
1548 g_return_val_if_fail ((return_type & G_SIGNAL_TYPE_STATIC_SCOPE) == 0, 0);
1549 if (return_type == (G_TYPE_NONE & ~G_SIGNAL_TYPE_STATIC_SCOPE))
1550 g_return_val_if_fail (accumulator == NULL, 0);
1552 g_return_val_if_fail (accu_data == NULL, 0);
1554 name = g_strdup (signal_name);
1555 g_strdelimit (name, G_STR_DELIMITERS ":^", '_'); /* FIXME do character checks like for types */
1559 signal_id = signal_id_lookup (g_quark_try_string (name), itype);
1560 node = LOOKUP_SIGNAL_NODE (signal_id);
1561 if (node && !node->destroyed)
1563 g_warning (G_STRLOC ": signal \"%s\" already exists in the `%s' %s",
1565 type_debug_name (node->itype),
1566 G_TYPE_IS_INTERFACE (node->itype) ? "interface" : "class ancestry");
1571 if (node && node->itype != itype)
1573 g_warning (G_STRLOC ": signal \"%s\" for type `%s' was previously created for type `%s'",
1575 type_debug_name (itype),
1576 type_debug_name (node->itype));
1581 for (i = 0; i < n_params; i++)
1582 if (!G_TYPE_IS_VALUE (param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE))
1584 g_warning (G_STRLOC ": parameter %d of type `%s' for signal \"%s::%s\" is not a value type",
1585 i + 1, type_debug_name (param_types[i]), type_debug_name (itype), name);
1590 if (return_type != G_TYPE_NONE && !G_TYPE_IS_VALUE (return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE))
1592 g_warning (G_STRLOC ": return value of type `%s' for signal \"%s::%s\" is not a value type",
1593 type_debug_name (return_type), type_debug_name (itype), name);
1598 if (return_type != G_TYPE_NONE &&
1599 (signal_flags & (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST | G_SIGNAL_RUN_CLEANUP)) == G_SIGNAL_RUN_FIRST)
1601 g_warning (G_STRLOC ": signal \"%s::%s\" has return type `%s' and is only G_SIGNAL_RUN_FIRST",
1602 type_debug_name (itype), name, type_debug_name (return_type));
1608 /* setup permanent portion of signal node */
1613 signal_id = g_n_signal_nodes++;
1614 node = g_new (SignalNode, 1);
1615 node->signal_id = signal_id;
1616 g_signal_nodes = g_renew (SignalNode*, g_signal_nodes, g_n_signal_nodes);
1617 g_signal_nodes[signal_id] = node;
1618 node->itype = itype;
1621 key.quark = g_quark_from_string (node->name);
1622 key.signal_id = signal_id;
1623 g_signal_key_bsa = g_bsearch_array_insert (g_signal_key_bsa, &g_signal_key_bconfig, &key);
1624 g_strdelimit (name, "_", '-');
1625 node->name = g_intern_string (name);
1626 key.quark = g_quark_from_string (name);
1627 g_signal_key_bsa = g_bsearch_array_insert (g_signal_key_bsa, &g_signal_key_bconfig, &key);
1629 TRACE(GOBJECT_SIGNAL_NEW(signal_id, name, itype));
1631 node->destroyed = FALSE;
1632 node->test_class_offset = 0;
1634 /* setup reinitializable portion */
1635 node->flags = signal_flags & G_SIGNAL_FLAGS_MASK;
1636 node->n_params = n_params;
1637 node->param_types = g_memdup (param_types, sizeof (GType) * n_params);
1638 node->return_type = return_type;
1639 node->class_closure_bsa = NULL;
1642 node->accumulator = g_new (SignalAccumulator, 1);
1643 node->accumulator->func = accumulator;
1644 node->accumulator->data = accu_data;
1647 node->accumulator = NULL;
1648 if (c_marshaller == NULL)
1649 c_marshaller = g_cclosure_marshal_generic;
1650 node->c_marshaller = c_marshaller;
1651 node->emission_hooks = NULL;
1653 signal_add_class_closure (node, 0, class_closure);
1654 else if (G_TYPE_IS_INSTANTIATABLE (itype) &&
1655 return_type == G_TYPE_NONE &&
1656 ~signal_flags & G_SIGNAL_MUST_COLLECT)
1658 /* optimize NOP emissions */
1659 node->test_class_offset = TEST_CLASS_MAGIC;
1669 * g_signal_new_valist:
1670 * @signal_name: the name for the signal
1671 * @itype: the type this signal pertains to. It will also pertain to
1672 * types which are derived from this type.
1673 * @signal_flags: a combination of #GSignalFlags specifying detail of when
1674 * the default handler is to be invoked. You should at least specify
1675 * %G_SIGNAL_RUN_FIRST or %G_SIGNAL_RUN_LAST.
1676 * @class_closure: The closure to invoke on signal emission; may be %NULL.
1677 * @accumulator: the accumulator for this signal; may be %NULL.
1678 * @accu_data: user data for the @accumulator.
1679 * @c_marshaller: (allow-none): the function to translate arrays of parameter
1680 * values to signal emissions into C language callback invocations or %NULL.
1681 * @return_type: the type of return value, or #G_TYPE_NONE for a signal
1682 * without a return value.
1683 * @n_params: the number of parameter types in @args.
1684 * @args: va_list of #GType, one for each parameter.
1686 * Creates a new signal. (This is usually done in the class initializer.)
1688 * See g_signal_new() for details on allowed signal names.
1690 * If c_marshaller is %NULL, g_cclosure_marshal_generic() will be used as
1691 * the marshaller for this signal.
1693 * Returns: the signal id
1696 g_signal_new_valist (const gchar *signal_name,
1698 GSignalFlags signal_flags,
1699 GClosure *class_closure,
1700 GSignalAccumulator accumulator,
1702 GSignalCMarshaller c_marshaller,
1713 param_types = g_new (GType, n_params);
1715 for (i = 0; i < n_params; i++)
1716 param_types[i] = va_arg (args, GType);
1721 signal_id = g_signal_newv (signal_name, itype, signal_flags,
1722 class_closure, accumulator, accu_data, c_marshaller,
1723 return_type, n_params, param_types);
1724 g_free (param_types);
1730 signal_destroy_R (SignalNode *signal_node)
1732 SignalNode node = *signal_node;
1734 signal_node->destroyed = TRUE;
1736 /* reentrancy caution, zero out real contents first */
1737 signal_node->test_class_offset = 0;
1738 signal_node->n_params = 0;
1739 signal_node->param_types = NULL;
1740 signal_node->return_type = 0;
1741 signal_node->class_closure_bsa = NULL;
1742 signal_node->accumulator = NULL;
1743 signal_node->c_marshaller = NULL;
1744 signal_node->emission_hooks = NULL;
1746 #ifdef G_ENABLE_DEBUG
1747 /* check current emissions */
1751 for (emission = (node.flags & G_SIGNAL_NO_RECURSE) ? g_restart_emissions : g_recursive_emissions;
1752 emission; emission = emission->next)
1753 if (emission->ihint.signal_id == node.signal_id)
1754 g_critical (G_STRLOC ": signal \"%s\" being destroyed is currently in emission (instance `%p')",
1755 node.name, emission->instance);
1759 /* free contents that need to
1762 g_free (node.param_types);
1763 if (node.class_closure_bsa)
1767 for (i = 0; i < node.class_closure_bsa->n_nodes; i++)
1769 ClassClosure *cc = g_bsearch_array_get_nth (node.class_closure_bsa, &g_class_closure_bconfig, i);
1771 g_closure_unref (cc->closure);
1773 g_bsearch_array_free (node.class_closure_bsa, &g_class_closure_bconfig);
1775 g_free (node.accumulator);
1776 if (node.emission_hooks)
1778 g_hook_list_clear (node.emission_hooks);
1779 g_free (node.emission_hooks);
1785 * g_signal_override_class_closure:
1786 * @signal_id: the signal id
1787 * @instance_type: the instance type on which to override the class closure
1789 * @class_closure: the closure.
1791 * Overrides the class closure (i.e. the default handler) for the given signal
1792 * for emissions on instances of @instance_type. @instance_type must be derived
1793 * from the type to which the signal belongs.
1795 * See g_signal_chain_from_overridden() and
1796 * g_signal_chain_from_overridden_handler() for how to chain up to the
1797 * parent class closure from inside the overridden one.
1800 g_signal_override_class_closure (guint signal_id,
1801 GType instance_type,
1802 GClosure *class_closure)
1806 g_return_if_fail (signal_id > 0);
1807 g_return_if_fail (class_closure != NULL);
1810 node = LOOKUP_SIGNAL_NODE (signal_id);
1811 node_check_deprecated (node);
1812 if (!g_type_is_a (instance_type, node->itype))
1813 g_warning ("%s: type `%s' cannot be overridden for signal id `%u'", G_STRLOC, type_debug_name (instance_type), signal_id);
1816 ClassClosure *cc = signal_find_class_closure (node, instance_type);
1818 if (cc && cc->instance_type == instance_type)
1819 g_warning ("%s: type `%s' is already overridden for signal id `%u'", G_STRLOC, type_debug_name (instance_type), signal_id);
1821 signal_add_class_closure (node, instance_type, class_closure);
1827 * g_signal_override_class_handler:
1828 * @signal_name: the name for the signal
1829 * @instance_type: the instance type on which to override the class handler
1831 * @class_handler: the handler.
1833 * Overrides the class closure (i.e. the default handler) for the
1834 * given signal for emissions on instances of @instance_type with
1835 * callabck @class_handler. @instance_type must be derived from the
1836 * type to which the signal belongs.
1838 * See g_signal_chain_from_overridden() and
1839 * g_signal_chain_from_overridden_handler() for how to chain up to the
1840 * parent class closure from inside the overridden one.
1845 g_signal_override_class_handler (const gchar *signal_name,
1846 GType instance_type,
1847 GCallback class_handler)
1851 g_return_if_fail (signal_name != NULL);
1852 g_return_if_fail (instance_type != G_TYPE_NONE);
1853 g_return_if_fail (class_handler != NULL);
1855 signal_id = g_signal_lookup (signal_name, instance_type);
1858 g_signal_override_class_closure (signal_id, instance_type,
1859 g_cclosure_new (class_handler, NULL, NULL));
1861 g_warning ("%s: signal name '%s' is invalid for type id '%"G_GSIZE_FORMAT"'",
1862 G_STRLOC, signal_name, instance_type);
1867 * g_signal_chain_from_overridden:
1868 * @instance_and_params: (array) the argument list of the signal emission.
1869 * The first element in the array is a #GValue for the instance the signal
1870 * is being emitted on. The rest are any arguments to be passed to the signal.
1871 * @return_value: Location for the return value.
1873 * Calls the original class closure of a signal. This function should only
1874 * be called from an overridden class closure; see
1875 * g_signal_override_class_closure() and
1876 * g_signal_override_class_handler().
1879 g_signal_chain_from_overridden (const GValue *instance_and_params,
1880 GValue *return_value)
1882 GType chain_type = 0, restore_type = 0;
1883 Emission *emission = NULL;
1884 GClosure *closure = NULL;
1888 g_return_if_fail (instance_and_params != NULL);
1889 instance = g_value_peek_pointer (instance_and_params);
1890 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
1893 emission = emission_find_innermost (instance);
1896 SignalNode *node = LOOKUP_SIGNAL_NODE (emission->ihint.signal_id);
1898 g_assert (node != NULL); /* paranoid */
1900 /* we should probably do the same parameter checks as g_signal_emit() here.
1902 if (emission->chain_type != G_TYPE_NONE)
1904 ClassClosure *cc = signal_find_class_closure (node, emission->chain_type);
1906 g_assert (cc != NULL); /* closure currently in call stack */
1908 n_params = node->n_params;
1909 restore_type = cc->instance_type;
1910 cc = signal_find_class_closure (node, g_type_parent (cc->instance_type));
1911 if (cc && cc->instance_type != restore_type)
1913 closure = cc->closure;
1914 chain_type = cc->instance_type;
1918 g_warning ("%s: signal id `%u' cannot be chained from current emission stage for instance `%p'", G_STRLOC, node->signal_id, instance);
1921 g_warning ("%s: no signal is currently being emitted for instance `%p'", G_STRLOC, instance);
1925 emission->chain_type = chain_type;
1927 g_closure_invoke (closure,
1930 instance_and_params,
1933 emission->chain_type = restore_type;
1939 * g_signal_chain_from_overridden_handler:
1940 * @instance: the instance the signal is being emitted on.
1941 * @...: parameters to be passed to the parent class closure, followed by a
1942 * location for the return value. If the return type of the signal
1943 * is #G_TYPE_NONE, the return value location can be omitted.
1945 * Calls the original class closure of a signal. This function should
1946 * only be called from an overridden class closure; see
1947 * g_signal_override_class_closure() and
1948 * g_signal_override_class_handler().
1953 g_signal_chain_from_overridden_handler (gpointer instance,
1956 GType chain_type = 0, restore_type = 0;
1957 Emission *emission = NULL;
1958 GClosure *closure = NULL;
1962 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
1965 emission = emission_find_innermost (instance);
1968 node = LOOKUP_SIGNAL_NODE (emission->ihint.signal_id);
1970 g_assert (node != NULL); /* paranoid */
1972 /* we should probably do the same parameter checks as g_signal_emit() here.
1974 if (emission->chain_type != G_TYPE_NONE)
1976 ClassClosure *cc = signal_find_class_closure (node, emission->chain_type);
1978 g_assert (cc != NULL); /* closure currently in call stack */
1980 n_params = node->n_params;
1981 restore_type = cc->instance_type;
1982 cc = signal_find_class_closure (node, g_type_parent (cc->instance_type));
1983 if (cc && cc->instance_type != restore_type)
1985 closure = cc->closure;
1986 chain_type = cc->instance_type;
1990 g_warning ("%s: signal id `%u' cannot be chained from current emission stage for instance `%p'", G_STRLOC, node->signal_id, instance);
1993 g_warning ("%s: no signal is currently being emitted for instance `%p'", G_STRLOC, instance);
1997 GValue *instance_and_params;
1998 GType signal_return_type;
1999 GValue *param_values;
2003 va_start (var_args, instance);
2005 signal_return_type = node->return_type;
2006 instance_and_params = g_slice_alloc0 (sizeof (GValue) * (n_params + 1));
2007 param_values = instance_and_params + 1;
2009 for (i = 0; i < node->n_params; i++)
2012 GType ptype = node->param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE;
2013 gboolean static_scope = node->param_types[i] & G_SIGNAL_TYPE_STATIC_SCOPE;
2016 G_VALUE_COLLECT_INIT (param_values + i, ptype,
2018 static_scope ? G_VALUE_NOCOPY_CONTENTS : 0,
2022 g_warning ("%s: %s", G_STRLOC, error);
2025 /* we purposely leak the value here, it might not be
2026 * in a sane state if an error condition occoured
2029 g_value_unset (param_values + i);
2031 g_slice_free1 (sizeof (GValue) * (n_params + 1), instance_and_params);
2039 instance_and_params->g_type = 0;
2040 g_value_init (instance_and_params, G_TYPE_FROM_INSTANCE (instance));
2041 g_value_set_instance (instance_and_params, instance);
2044 emission->chain_type = chain_type;
2047 if (signal_return_type == G_TYPE_NONE)
2049 g_closure_invoke (closure,
2052 instance_and_params,
2057 GValue return_value = G_VALUE_INIT;
2058 gchar *error = NULL;
2059 GType rtype = signal_return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE;
2060 gboolean static_scope = signal_return_type & G_SIGNAL_TYPE_STATIC_SCOPE;
2062 g_value_init (&return_value, rtype);
2064 g_closure_invoke (closure,
2067 instance_and_params,
2070 G_VALUE_LCOPY (&return_value,
2072 static_scope ? G_VALUE_NOCOPY_CONTENTS : 0,
2076 g_value_unset (&return_value);
2080 g_warning ("%s: %s", G_STRLOC, error);
2083 /* we purposely leak the value here, it might not be
2084 * in a sane state if an error condition occurred
2089 for (i = 0; i < n_params; i++)
2090 g_value_unset (param_values + i);
2091 g_value_unset (instance_and_params);
2092 g_slice_free1 (sizeof (GValue) * (n_params + 1), instance_and_params);
2097 emission->chain_type = restore_type;
2103 * g_signal_get_invocation_hint:
2104 * @instance: the instance to query
2106 * Returns the invocation hint of the innermost signal emission of instance.
2108 * Returns: (transfer none): the invocation hint of the innermost signal emission.
2110 GSignalInvocationHint*
2111 g_signal_get_invocation_hint (gpointer instance)
2113 Emission *emission = NULL;
2115 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), NULL);
2118 emission = emission_find_innermost (instance);
2121 return emission ? &emission->ihint : NULL;
2125 * g_signal_connect_closure_by_id:
2126 * @instance: the instance to connect to.
2127 * @signal_id: the id of the signal.
2128 * @detail: the detail.
2129 * @closure: the closure to connect.
2130 * @after: whether the handler should be called before or after the
2131 * default handler of the signal.
2133 * Connects a closure to a signal for a particular object.
2135 * Returns: the handler id
2138 g_signal_connect_closure_by_id (gpointer instance,
2145 gulong handler_seq_no = 0;
2147 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
2148 g_return_val_if_fail (signal_id > 0, 0);
2149 g_return_val_if_fail (closure != NULL, 0);
2152 node = LOOKUP_SIGNAL_NODE (signal_id);
2155 if (detail && !(node->flags & G_SIGNAL_DETAILED))
2156 g_warning ("%s: signal id `%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
2157 else if (!g_type_is_a (G_TYPE_FROM_INSTANCE (instance), node->itype))
2158 g_warning ("%s: signal id `%u' is invalid for instance `%p'", G_STRLOC, signal_id, instance);
2161 Handler *handler = handler_new (after);
2163 handler_seq_no = handler->sequential_number;
2164 handler->detail = detail;
2165 handler->closure = g_closure_ref (closure);
2166 g_closure_sink (closure);
2167 handler_insert (signal_id, instance, handler);
2168 if (node->c_marshaller && G_CLOSURE_NEEDS_MARSHAL (closure))
2169 g_closure_set_marshal (closure, node->c_marshaller);
2173 g_warning ("%s: signal id `%u' is invalid for instance `%p'", G_STRLOC, signal_id, instance);
2176 return handler_seq_no;
2180 * g_signal_connect_closure:
2181 * @instance: the instance to connect to.
2182 * @detailed_signal: a string of the form "signal-name::detail".
2183 * @closure: the closure to connect.
2184 * @after: whether the handler should be called before or after the
2185 * default handler of the signal.
2187 * Connects a closure to a signal for a particular object.
2189 * Returns: the handler id
2192 g_signal_connect_closure (gpointer instance,
2193 const gchar *detailed_signal,
2198 gulong handler_seq_no = 0;
2202 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
2203 g_return_val_if_fail (detailed_signal != NULL, 0);
2204 g_return_val_if_fail (closure != NULL, 0);
2207 itype = G_TYPE_FROM_INSTANCE (instance);
2208 signal_id = signal_parse_name (detailed_signal, itype, &detail, TRUE);
2211 SignalNode *node = LOOKUP_SIGNAL_NODE (signal_id);
2213 if (detail && !(node->flags & G_SIGNAL_DETAILED))
2214 g_warning ("%s: signal `%s' does not support details", G_STRLOC, detailed_signal);
2215 else if (!g_type_is_a (itype, node->itype))
2216 g_warning ("%s: signal `%s' is invalid for instance `%p'", G_STRLOC, detailed_signal, instance);
2219 Handler *handler = handler_new (after);
2221 handler_seq_no = handler->sequential_number;
2222 handler->detail = detail;
2223 handler->closure = g_closure_ref (closure);
2224 g_closure_sink (closure);
2225 handler_insert (signal_id, instance, handler);
2226 if (node->c_marshaller && G_CLOSURE_NEEDS_MARSHAL (handler->closure))
2227 g_closure_set_marshal (handler->closure, node->c_marshaller);
2231 g_warning ("%s: signal `%s' is invalid for instance `%p'", G_STRLOC, detailed_signal, instance);
2234 return handler_seq_no;
2238 node_check_deprecated (const SignalNode *node)
2240 static const gchar * g_enable_diagnostic = NULL;
2242 if (G_UNLIKELY (!g_enable_diagnostic))
2244 g_enable_diagnostic = g_getenv ("G_ENABLE_DIAGNOSTIC");
2245 if (!g_enable_diagnostic)
2246 g_enable_diagnostic = "0";
2249 if (g_enable_diagnostic[0] == '1')
2251 if (node->flags & G_SIGNAL_DEPRECATED)
2253 g_warning ("The signal %s::%s is deprecated and shouldn't be used "
2254 "anymore. It will be removed in a future version.",
2255 type_debug_name (node->itype), node->name);
2261 * g_signal_connect_data:
2262 * @instance: the instance to connect to.
2263 * @detailed_signal: a string of the form "signal-name::detail".
2264 * @c_handler: the #GCallback to connect.
2265 * @data: data to pass to @c_handler calls.
2266 * @destroy_data: a #GClosureNotify for @data.
2267 * @connect_flags: a combination of #GConnectFlags.
2269 * Connects a #GCallback function to a signal for a particular object. Similar
2270 * to g_signal_connect(), but allows to provide a #GClosureNotify for the data
2271 * which will be called when the signal handler is disconnected and no longer
2272 * used. Specify @connect_flags if you need <literal>..._after()</literal> or
2273 * <literal>..._swapped()</literal> variants of this function.
2275 * Returns: the handler id
2278 g_signal_connect_data (gpointer instance,
2279 const gchar *detailed_signal,
2280 GCallback c_handler,
2282 GClosureNotify destroy_data,
2283 GConnectFlags connect_flags)
2286 gulong handler_seq_no = 0;
2289 gboolean swapped, after;
2291 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
2292 g_return_val_if_fail (detailed_signal != NULL, 0);
2293 g_return_val_if_fail (c_handler != NULL, 0);
2295 swapped = (connect_flags & G_CONNECT_SWAPPED) != FALSE;
2296 after = (connect_flags & G_CONNECT_AFTER) != FALSE;
2299 itype = G_TYPE_FROM_INSTANCE (instance);
2300 signal_id = signal_parse_name (detailed_signal, itype, &detail, TRUE);
2303 SignalNode *node = LOOKUP_SIGNAL_NODE (signal_id);
2305 node_check_deprecated (node);
2307 if (detail && !(node->flags & G_SIGNAL_DETAILED))
2308 g_warning ("%s: signal `%s' does not support details", G_STRLOC, detailed_signal);
2309 else if (!g_type_is_a (itype, node->itype))
2310 g_warning ("%s: signal `%s' is invalid for instance `%p'", G_STRLOC, detailed_signal, instance);
2313 Handler *handler = handler_new (after);
2315 handler_seq_no = handler->sequential_number;
2316 handler->detail = detail;
2317 handler->closure = g_closure_ref ((swapped ? g_cclosure_new_swap : g_cclosure_new) (c_handler, data, destroy_data));
2318 g_closure_sink (handler->closure);
2319 handler_insert (signal_id, instance, handler);
2320 if (node->c_marshaller && G_CLOSURE_NEEDS_MARSHAL (handler->closure))
2321 g_closure_set_marshal (handler->closure, node->c_marshaller);
2325 g_warning ("%s: signal `%s' is invalid for instance `%p'", G_STRLOC, detailed_signal, instance);
2328 return handler_seq_no;
2332 * g_signal_handler_block:
2333 * @instance: The instance to block the signal handler of.
2334 * @handler_id: Handler id of the handler to be blocked.
2336 * Blocks a handler of an instance so it will not be called during any
2337 * signal emissions unless it is unblocked again. Thus "blocking" a
2338 * signal handler means to temporarily deactive it, a signal handler
2339 * has to be unblocked exactly the same amount of times it has been
2340 * blocked before to become active again.
2342 * The @handler_id has to be a valid signal handler id, connected to a
2343 * signal of @instance.
2346 g_signal_handler_block (gpointer instance,
2351 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
2352 g_return_if_fail (handler_id > 0);
2355 handler = handler_lookup (instance, handler_id, NULL);
2358 #ifndef G_DISABLE_CHECKS
2359 if (handler->block_count >= HANDLER_MAX_BLOCK_COUNT - 1)
2360 g_error (G_STRLOC ": handler block_count overflow, %s", REPORT_BUG);
2362 handler->block_count += 1;
2365 g_warning ("%s: instance `%p' has no handler with id `%lu'", G_STRLOC, instance, handler_id);
2370 * g_signal_handler_unblock:
2371 * @instance: The instance to unblock the signal handler of.
2372 * @handler_id: Handler id of the handler to be unblocked.
2374 * Undoes the effect of a previous g_signal_handler_block() call. A
2375 * blocked handler is skipped during signal emissions and will not be
2376 * invoked, unblocking it (for exactly the amount of times it has been
2377 * blocked before) reverts its "blocked" state, so the handler will be
2378 * recognized by the signal system and is called upon future or
2379 * currently ongoing signal emissions (since the order in which
2380 * handlers are called during signal emissions is deterministic,
2381 * whether the unblocked handler in question is called as part of a
2382 * currently ongoing emission depends on how far that emission has
2385 * The @handler_id has to be a valid id of a signal handler that is
2386 * connected to a signal of @instance and is currently blocked.
2389 g_signal_handler_unblock (gpointer instance,
2394 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
2395 g_return_if_fail (handler_id > 0);
2398 handler = handler_lookup (instance, handler_id, NULL);
2401 if (handler->block_count)
2402 handler->block_count -= 1;
2404 g_warning (G_STRLOC ": handler `%lu' of instance `%p' is not blocked", handler_id, instance);
2407 g_warning ("%s: instance `%p' has no handler with id `%lu'", G_STRLOC, instance, handler_id);
2412 * g_signal_handler_disconnect:
2413 * @instance: The instance to remove the signal handler from.
2414 * @handler_id: Handler id of the handler to be disconnected.
2416 * Disconnects a handler from an instance so it will not be called during
2417 * any future or currently ongoing emissions of the signal it has been
2418 * connected to. The @handler_id becomes invalid and may be reused.
2420 * The @handler_id has to be a valid signal handler id, connected to a
2421 * signal of @instance.
2424 g_signal_handler_disconnect (gpointer instance,
2430 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
2431 g_return_if_fail (handler_id > 0);
2434 handler = handler_lookup (instance, handler_id, &signal_id);
2437 handler->sequential_number = 0;
2438 handler->block_count = 1;
2439 handler_unref_R (signal_id, instance, handler);
2442 g_warning ("%s: instance `%p' has no handler with id `%lu'", G_STRLOC, instance, handler_id);
2447 * g_signal_handler_is_connected:
2448 * @instance: The instance where a signal handler is sought.
2449 * @handler_id: the handler id.
2451 * Returns whether @handler_id is the id of a handler connected to @instance.
2453 * Returns: whether @handler_id identifies a handler connected to @instance.
2456 g_signal_handler_is_connected (gpointer instance,
2462 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), FALSE);
2465 handler = handler_lookup (instance, handler_id, NULL);
2466 connected = handler != NULL;
2473 g_signal_handlers_destroy (gpointer instance)
2475 GBSearchArray *hlbsa;
2477 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
2480 hlbsa = g_hash_table_lookup (g_handler_list_bsa_ht, instance);
2485 /* reentrancy caution, delete instance trace first */
2486 g_hash_table_remove (g_handler_list_bsa_ht, instance);
2488 for (i = 0; i < hlbsa->n_nodes; i++)
2490 HandlerList *hlist = g_bsearch_array_get_nth (hlbsa, &g_signal_hlbsa_bconfig, i);
2491 Handler *handler = hlist->handlers;
2495 Handler *tmp = handler;
2497 handler = tmp->next;
2498 tmp->block_count = 1;
2499 /* cruel unlink, this works because _all_ handlers vanish */
2502 if (tmp->sequential_number)
2504 tmp->sequential_number = 0;
2505 handler_unref_R (0, NULL, tmp);
2509 g_bsearch_array_free (hlbsa, &g_signal_hlbsa_bconfig);
2515 * g_signal_handler_find:
2516 * @instance: The instance owning the signal handler to be found.
2517 * @mask: Mask indicating which of @signal_id, @detail, @closure, @func
2518 * and/or @data the handler has to match.
2519 * @signal_id: Signal the handler has to be connected to.
2520 * @detail: Signal detail the handler has to be connected to.
2521 * @closure: (allow-none): The closure the handler will invoke.
2522 * @func: The C closure callback of the handler (useless for non-C closures).
2523 * @data: The closure data of the handler's closure.
2525 * Finds the first signal handler that matches certain selection criteria.
2526 * The criteria mask is passed as an OR-ed combination of #GSignalMatchType
2527 * flags, and the criteria values are passed as arguments.
2528 * The match @mask has to be non-0 for successful matches.
2529 * If no handler was found, 0 is returned.
2531 * Returns: A valid non-0 signal handler id for a successful match.
2534 g_signal_handler_find (gpointer instance,
2535 GSignalMatchType mask,
2542 gulong handler_seq_no = 0;
2544 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
2545 g_return_val_if_fail ((mask & ~G_SIGNAL_MATCH_MASK) == 0, 0);
2547 if (mask & G_SIGNAL_MATCH_MASK)
2549 HandlerMatch *mlist;
2552 mlist = handlers_find (instance, mask, signal_id, detail, closure, func, data, TRUE);
2555 handler_seq_no = mlist->handler->sequential_number;
2556 handler_match_free1_R (mlist, instance);
2561 return handler_seq_no;
2565 signal_handlers_foreach_matched_R (gpointer instance,
2566 GSignalMatchType mask,
2572 void (*callback) (gpointer instance,
2573 gulong handler_seq_no))
2575 HandlerMatch *mlist;
2576 guint n_handlers = 0;
2578 mlist = handlers_find (instance, mask, signal_id, detail, closure, func, data, FALSE);
2582 if (mlist->handler->sequential_number)
2585 callback (instance, mlist->handler->sequential_number);
2588 mlist = handler_match_free1_R (mlist, instance);
2595 * g_signal_handlers_block_matched:
2596 * @instance: The instance to block handlers from.
2597 * @mask: Mask indicating which of @signal_id, @detail, @closure, @func
2598 * and/or @data the handlers have to match.
2599 * @signal_id: Signal the handlers have to be connected to.
2600 * @detail: Signal detail the handlers have to be connected to.
2601 * @closure: (allow-none): The closure the handlers will invoke.
2602 * @func: The C closure callback of the handlers (useless for non-C closures).
2603 * @data: The closure data of the handlers' closures.
2605 * Blocks all handlers on an instance that match a certain selection criteria.
2606 * The criteria mask is passed as an OR-ed combination of #GSignalMatchType
2607 * flags, and the criteria values are passed as arguments.
2608 * Passing at least one of the %G_SIGNAL_MATCH_CLOSURE, %G_SIGNAL_MATCH_FUNC
2609 * or %G_SIGNAL_MATCH_DATA match flags is required for successful matches.
2610 * If no handlers were found, 0 is returned, the number of blocked handlers
2613 * Returns: The number of handlers that matched.
2616 g_signal_handlers_block_matched (gpointer instance,
2617 GSignalMatchType mask,
2624 guint n_handlers = 0;
2626 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
2627 g_return_val_if_fail ((mask & ~G_SIGNAL_MATCH_MASK) == 0, 0);
2629 if (mask & (G_SIGNAL_MATCH_CLOSURE | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA))
2632 n_handlers = signal_handlers_foreach_matched_R (instance, mask, signal_id, detail,
2633 closure, func, data,
2634 g_signal_handler_block);
2642 * g_signal_handlers_unblock_matched:
2643 * @instance: The instance to unblock handlers from.
2644 * @mask: Mask indicating which of @signal_id, @detail, @closure, @func
2645 * and/or @data the handlers have to match.
2646 * @signal_id: Signal the handlers have to be connected to.
2647 * @detail: Signal detail the handlers have to be connected to.
2648 * @closure: (allow-none): The closure the handlers will invoke.
2649 * @func: The C closure callback of the handlers (useless for non-C closures).
2650 * @data: The closure data of the handlers' closures.
2652 * Unblocks all handlers on an instance that match a certain selection
2653 * criteria. The criteria mask is passed as an OR-ed combination of
2654 * #GSignalMatchType flags, and the criteria values are passed as arguments.
2655 * Passing at least one of the %G_SIGNAL_MATCH_CLOSURE, %G_SIGNAL_MATCH_FUNC
2656 * or %G_SIGNAL_MATCH_DATA match flags is required for successful matches.
2657 * If no handlers were found, 0 is returned, the number of unblocked handlers
2658 * otherwise. The match criteria should not apply to any handlers that are
2659 * not currently blocked.
2661 * Returns: The number of handlers that matched.
2664 g_signal_handlers_unblock_matched (gpointer instance,
2665 GSignalMatchType mask,
2672 guint n_handlers = 0;
2674 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
2675 g_return_val_if_fail ((mask & ~G_SIGNAL_MATCH_MASK) == 0, 0);
2677 if (mask & (G_SIGNAL_MATCH_CLOSURE | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA))
2680 n_handlers = signal_handlers_foreach_matched_R (instance, mask, signal_id, detail,
2681 closure, func, data,
2682 g_signal_handler_unblock);
2690 * g_signal_handlers_disconnect_matched:
2691 * @instance: The instance to remove handlers from.
2692 * @mask: Mask indicating which of @signal_id, @detail, @closure, @func
2693 * and/or @data the handlers have to match.
2694 * @signal_id: Signal the handlers have to be connected to.
2695 * @detail: Signal detail the handlers have to be connected to.
2696 * @closure: (allow-none): The closure the handlers will invoke.
2697 * @func: The C closure callback of the handlers (useless for non-C closures).
2698 * @data: The closure data of the handlers' closures.
2700 * Disconnects all handlers on an instance that match a certain
2701 * selection criteria. The criteria mask is passed as an OR-ed
2702 * combination of #GSignalMatchType flags, and the criteria values are
2703 * passed as arguments. Passing at least one of the
2704 * %G_SIGNAL_MATCH_CLOSURE, %G_SIGNAL_MATCH_FUNC or
2705 * %G_SIGNAL_MATCH_DATA match flags is required for successful
2706 * matches. If no handlers were found, 0 is returned, the number of
2707 * disconnected handlers otherwise.
2709 * Returns: The number of handlers that matched.
2712 g_signal_handlers_disconnect_matched (gpointer instance,
2713 GSignalMatchType mask,
2720 guint n_handlers = 0;
2722 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
2723 g_return_val_if_fail ((mask & ~G_SIGNAL_MATCH_MASK) == 0, 0);
2725 if (mask & (G_SIGNAL_MATCH_CLOSURE | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA))
2728 n_handlers = signal_handlers_foreach_matched_R (instance, mask, signal_id, detail,
2729 closure, func, data,
2730 g_signal_handler_disconnect);
2738 * g_signal_has_handler_pending:
2739 * @instance: the object whose signal handlers are sought.
2740 * @signal_id: the signal id.
2741 * @detail: the detail.
2742 * @may_be_blocked: whether blocked handlers should count as match.
2744 * Returns whether there are any handlers connected to @instance for the
2745 * given signal id and detail.
2747 * One example of when you might use this is when the arguments to the
2748 * signal are difficult to compute. A class implementor may opt to not
2749 * emit the signal if no one is attached anyway, thus saving the cost
2750 * of building the arguments.
2752 * Returns: %TRUE if a handler is connected to the signal, %FALSE
2756 g_signal_has_handler_pending (gpointer instance,
2759 gboolean may_be_blocked)
2761 HandlerMatch *mlist;
2762 gboolean has_pending;
2764 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), FALSE);
2765 g_return_val_if_fail (signal_id > 0, FALSE);
2770 SignalNode *node = LOOKUP_SIGNAL_NODE (signal_id);
2772 if (!(node->flags & G_SIGNAL_DETAILED))
2774 g_warning ("%s: signal id `%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
2779 mlist = handlers_find (instance,
2780 (G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | (may_be_blocked ? 0 : G_SIGNAL_MATCH_UNBLOCKED)),
2781 signal_id, detail, NULL, NULL, NULL, TRUE);
2785 handler_match_free1_R (mlist, instance);
2788 has_pending = FALSE;
2794 static inline gboolean
2795 signal_check_skip_emission (SignalNode *node,
2801 /* are we able to check for NULL class handlers? */
2802 if (!node->test_class_offset)
2805 /* are there emission hooks pending? */
2806 if (node->emission_hooks && node->emission_hooks->hooks)
2809 /* is there a non-NULL class handler? */
2810 if (node->test_class_offset != TEST_CLASS_MAGIC)
2812 GTypeClass *class = G_TYPE_INSTANCE_GET_CLASS (instance, G_TYPE_FROM_INSTANCE (instance), GTypeClass);
2814 if (G_STRUCT_MEMBER (gpointer, class, node->test_class_offset))
2818 /* are signals being debugged? */
2819 #ifdef G_ENABLE_DEBUG
2820 IF_DEBUG (SIGNALS, g_trace_instance_signals || g_trap_instance_signals)
2822 #endif /* G_ENABLE_DEBUG */
2824 /* is this a no-recurse signal already in emission? */
2825 if (node->flags & G_SIGNAL_NO_RECURSE &&
2826 emission_find (g_restart_emissions, node->signal_id, detail, instance))
2829 /* do we have pending handlers? */
2830 hlist = handler_list_lookup (node->signal_id, instance);
2831 if (hlist && hlist->handlers)
2834 /* none of the above, no emission required */
2840 * @instance_and_params: (array): argument list for the signal emission.
2841 * The first element in the array is a #GValue for the instance the signal
2842 * is being emitted on. The rest are any arguments to be passed to the signal.
2843 * @signal_id: the signal id
2844 * @detail: the detail
2845 * @return_value: Location to store the return value of the signal emission.
2849 * Note that g_signal_emitv() doesn't change @return_value if no handlers are
2850 * connected, in contrast to g_signal_emit() and g_signal_emit_valist().
2853 g_signal_emitv (const GValue *instance_and_params,
2856 GValue *return_value)
2860 #ifdef G_ENABLE_DEBUG
2861 const GValue *param_values;
2865 g_return_if_fail (instance_and_params != NULL);
2866 instance = g_value_peek_pointer (instance_and_params);
2867 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
2868 g_return_if_fail (signal_id > 0);
2870 #ifdef G_ENABLE_DEBUG
2871 param_values = instance_and_params + 1;
2875 node = LOOKUP_SIGNAL_NODE (signal_id);
2876 if (!node || !g_type_is_a (G_TYPE_FROM_INSTANCE (instance), node->itype))
2878 g_warning ("%s: signal id `%u' is invalid for instance `%p'", G_STRLOC, signal_id, instance);
2882 #ifdef G_ENABLE_DEBUG
2883 if (detail && !(node->flags & G_SIGNAL_DETAILED))
2885 g_warning ("%s: signal id `%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
2889 for (i = 0; i < node->n_params; i++)
2890 if (!G_TYPE_CHECK_VALUE_TYPE (param_values + i, node->param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE))
2892 g_critical ("%s: value for `%s' parameter %u for signal \"%s\" is of type `%s'",
2894 type_debug_name (node->param_types[i]),
2897 G_VALUE_TYPE_NAME (param_values + i));
2901 if (node->return_type != G_TYPE_NONE)
2905 g_critical ("%s: return value `%s' for signal \"%s\" is (NULL)",
2907 type_debug_name (node->return_type),
2912 else if (!node->accumulator && !G_TYPE_CHECK_VALUE_TYPE (return_value, node->return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE))
2914 g_critical ("%s: return value `%s' for signal \"%s\" is of type `%s'",
2916 type_debug_name (node->return_type),
2918 G_VALUE_TYPE_NAME (return_value));
2924 return_value = NULL;
2925 #endif /* G_ENABLE_DEBUG */
2927 /* optimize NOP emissions */
2928 if (signal_check_skip_emission (node, instance, detail))
2930 /* nothing to do to emit this signal */
2932 /* g_printerr ("omitting emission of \"%s\"\n", node->name); */
2937 signal_emit_unlocked_R (node, detail, instance, return_value, instance_and_params);
2941 * g_signal_emit_valist:
2942 * @instance: the instance the signal is being emitted on.
2943 * @signal_id: the signal id
2944 * @detail: the detail
2945 * @var_args: a list of parameters to be passed to the signal, followed by a
2946 * location for the return value. If the return type of the signal
2947 * is #G_TYPE_NONE, the return value location can be omitted.
2951 * Note that g_signal_emit_valist() resets the return value to the default
2952 * if no handlers are connected, in contrast to g_signal_emitv().
2955 g_signal_emit_valist (gpointer instance,
2960 GValue *instance_and_params;
2961 GType signal_return_type;
2962 GValue *param_values;
2966 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
2967 g_return_if_fail (signal_id > 0);
2970 node = LOOKUP_SIGNAL_NODE (signal_id);
2971 if (!node || !g_type_is_a (G_TYPE_FROM_INSTANCE (instance), node->itype))
2973 g_warning ("%s: signal id `%u' is invalid for instance `%p'", G_STRLOC, signal_id, instance);
2977 #ifndef G_DISABLE_CHECKS
2978 if (detail && !(node->flags & G_SIGNAL_DETAILED))
2980 g_warning ("%s: signal id `%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
2984 #endif /* !G_DISABLE_CHECKS */
2986 /* optimize NOP emissions */
2987 if (signal_check_skip_emission (node, instance, detail))
2989 /* nothing to do to emit this signal */
2991 /* g_printerr ("omitting emission of \"%s\"\n", node->name); */
2995 n_params = node->n_params;
2996 signal_return_type = node->return_type;
2997 instance_and_params = g_slice_alloc0 (sizeof (GValue) * (n_params + 1));
2998 param_values = instance_and_params + 1;
3000 for (i = 0; i < node->n_params; i++)
3003 GType ptype = node->param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE;
3004 gboolean static_scope = node->param_types[i] & G_SIGNAL_TYPE_STATIC_SCOPE;
3007 G_VALUE_COLLECT_INIT (param_values + i, ptype,
3009 static_scope ? G_VALUE_NOCOPY_CONTENTS : 0,
3013 g_warning ("%s: %s", G_STRLOC, error);
3016 /* we purposely leak the value here, it might not be
3017 * in a sane state if an error condition occoured
3020 g_value_unset (param_values + i);
3022 g_slice_free1 (sizeof (GValue) * (n_params + 1), instance_and_params);
3029 instance_and_params->g_type = 0;
3030 g_value_init (instance_and_params, G_TYPE_FROM_INSTANCE (instance));
3031 g_value_set_instance (instance_and_params, instance);
3032 if (signal_return_type == G_TYPE_NONE)
3033 signal_emit_unlocked_R (node, detail, instance, NULL, instance_and_params);
3036 GValue return_value = G_VALUE_INIT;
3037 gchar *error = NULL;
3038 GType rtype = signal_return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE;
3039 gboolean static_scope = signal_return_type & G_SIGNAL_TYPE_STATIC_SCOPE;
3041 g_value_init (&return_value, rtype);
3043 signal_emit_unlocked_R (node, detail, instance, &return_value, instance_and_params);
3045 G_VALUE_LCOPY (&return_value,
3047 static_scope ? G_VALUE_NOCOPY_CONTENTS : 0,
3050 g_value_unset (&return_value);
3053 g_warning ("%s: %s", G_STRLOC, error);
3056 /* we purposely leak the value here, it might not be
3057 * in a sane state if an error condition occurred
3061 for (i = 0; i < n_params; i++)
3062 g_value_unset (param_values + i);
3063 g_value_unset (instance_and_params);
3064 g_slice_free1 (sizeof (GValue) * (n_params + 1), instance_and_params);
3069 * @instance: the instance the signal is being emitted on.
3070 * @signal_id: the signal id
3071 * @detail: the detail
3072 * @...: parameters to be passed to the signal, followed by a
3073 * location for the return value. If the return type of the signal
3074 * is #G_TYPE_NONE, the return value location can be omitted.
3078 * Note that g_signal_emit() resets the return value to the default
3079 * if no handlers are connected, in contrast to g_signal_emitv().
3082 g_signal_emit (gpointer instance,
3089 va_start (var_args, detail);
3090 g_signal_emit_valist (instance, signal_id, detail, var_args);
3095 * g_signal_emit_by_name:
3096 * @instance: the instance the signal is being emitted on.
3097 * @detailed_signal: a string of the form "signal-name::detail".
3098 * @...: parameters to be passed to the signal, followed by a
3099 * location for the return value. If the return type of the signal
3100 * is #G_TYPE_NONE, the return value location can be omitted.
3104 * Note that g_signal_emit_by_name() resets the return value to the default
3105 * if no handlers are connected, in contrast to g_signal_emitv().
3108 g_signal_emit_by_name (gpointer instance,
3109 const gchar *detailed_signal,
3115 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
3116 g_return_if_fail (detailed_signal != NULL);
3119 signal_id = signal_parse_name (detailed_signal, G_TYPE_FROM_INSTANCE (instance), &detail, TRUE);
3126 va_start (var_args, detailed_signal);
3127 g_signal_emit_valist (instance, signal_id, detail, var_args);
3131 g_warning ("%s: signal name `%s' is invalid for instance `%p'", G_STRLOC, detailed_signal, instance);
3134 static inline gboolean
3135 accumulate (GSignalInvocationHint *ihint,
3136 GValue *return_accu,
3137 GValue *handler_return,
3138 SignalAccumulator *accumulator)
3140 gboolean continue_emission;
3145 continue_emission = accumulator->func (ihint, return_accu, handler_return, accumulator->data);
3146 g_value_reset (handler_return);
3148 return continue_emission;
3152 signal_emit_unlocked_R (SignalNode *node,
3155 GValue *emission_return,
3156 const GValue *instance_and_params)
3158 SignalAccumulator *accumulator;
3160 GClosure *class_closure;
3162 Handler *handler_list = NULL;
3163 GValue *return_accu, accu = G_VALUE_INIT;
3165 gulong max_sequential_handler_number;
3166 gboolean return_value_altered = FALSE;
3168 #ifdef G_ENABLE_DEBUG
3169 IF_DEBUG (SIGNALS, g_trace_instance_signals == instance || g_trap_instance_signals == instance)
3171 g_message ("%s::%s(%u) emitted (instance=%p, signal-node=%p)",
3172 g_type_name (G_TYPE_FROM_INSTANCE (instance)),
3175 if (g_trap_instance_signals == instance)
3178 #endif /* G_ENABLE_DEBUG */
3180 TRACE(GOBJECT_SIGNAL_EMIT(node->signal_id, detail, instance, G_TYPE_FROM_INSTANCE (instance)));
3183 signal_id = node->signal_id;
3184 if (node->flags & G_SIGNAL_NO_RECURSE)
3186 Emission *node = emission_find (g_restart_emissions, signal_id, detail, instance);
3190 node->state = EMISSION_RESTART;
3192 return return_value_altered;
3195 accumulator = node->accumulator;
3199 g_value_init (&accu, node->return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE);
3200 return_accu = &accu;
3204 return_accu = emission_return;
3205 emission.instance = instance;
3206 emission.ihint.signal_id = node->signal_id;
3207 emission.ihint.detail = detail;
3208 emission.ihint.run_type = 0;
3210 emission.chain_type = G_TYPE_NONE;
3211 emission_push ((node->flags & G_SIGNAL_NO_RECURSE) ? &g_restart_emissions : &g_recursive_emissions, &emission);
3212 class_closure = signal_lookup_closure (node, instance);
3217 handler_unref_R (signal_id, instance, handler_list);
3218 max_sequential_handler_number = g_handler_sequential_number;
3219 hlist = handler_list_lookup (signal_id, instance);
3220 handler_list = hlist ? hlist->handlers : NULL;
3222 handler_ref (handler_list);
3224 emission.ihint.run_type = G_SIGNAL_RUN_FIRST;
3226 if ((node->flags & G_SIGNAL_RUN_FIRST) && class_closure)
3228 emission.state = EMISSION_RUN;
3230 emission.chain_type = G_TYPE_FROM_INSTANCE (instance);
3232 g_closure_invoke (class_closure,
3235 instance_and_params,
3237 if (!accumulate (&emission.ihint, emission_return, &accu, accumulator) &&
3238 emission.state == EMISSION_RUN)
3239 emission.state = EMISSION_STOP;
3241 emission.chain_type = G_TYPE_NONE;
3242 return_value_altered = TRUE;
3244 if (emission.state == EMISSION_STOP)
3246 else if (emission.state == EMISSION_RESTART)
3250 if (node->emission_hooks)
3252 gboolean need_destroy, was_in_call, may_recurse = TRUE;
3255 emission.state = EMISSION_HOOK;
3256 hook = g_hook_first_valid (node->emission_hooks, may_recurse);
3259 SignalHook *signal_hook = SIGNAL_HOOK (hook);
3261 if (!signal_hook->detail || signal_hook->detail == detail)
3263 GSignalEmissionHook hook_func = (GSignalEmissionHook) hook->func;
3265 was_in_call = G_HOOK_IN_CALL (hook);
3266 hook->flags |= G_HOOK_FLAG_IN_CALL;
3268 need_destroy = !hook_func (&emission.ihint, node->n_params + 1, instance_and_params, hook->data);
3271 hook->flags &= ~G_HOOK_FLAG_IN_CALL;
3273 g_hook_destroy_link (node->emission_hooks, hook);
3275 hook = g_hook_next_valid (node->emission_hooks, hook, may_recurse);
3278 if (emission.state == EMISSION_RESTART)
3284 Handler *handler = handler_list;
3286 emission.state = EMISSION_RUN;
3287 handler_ref (handler);
3294 handler_unref_R (signal_id, instance, handler_list);
3295 handler_list = handler;
3298 else if (!handler->block_count && (!handler->detail || handler->detail == detail) &&
3299 handler->sequential_number < max_sequential_handler_number)
3302 g_closure_invoke (handler->closure,
3305 instance_and_params,
3307 if (!accumulate (&emission.ihint, emission_return, &accu, accumulator) &&
3308 emission.state == EMISSION_RUN)
3309 emission.state = EMISSION_STOP;
3311 return_value_altered = TRUE;
3313 tmp = emission.state == EMISSION_RUN ? handler->next : NULL;
3316 tmp = handler->next;
3320 handler_unref_R (signal_id, instance, handler_list);
3321 handler_list = handler;
3326 if (emission.state == EMISSION_STOP)
3328 else if (emission.state == EMISSION_RESTART)
3332 emission.ihint.run_type = G_SIGNAL_RUN_LAST;
3334 if ((node->flags & G_SIGNAL_RUN_LAST) && class_closure)
3336 emission.state = EMISSION_RUN;
3338 emission.chain_type = G_TYPE_FROM_INSTANCE (instance);
3340 g_closure_invoke (class_closure,
3343 instance_and_params,
3345 if (!accumulate (&emission.ihint, emission_return, &accu, accumulator) &&
3346 emission.state == EMISSION_RUN)
3347 emission.state = EMISSION_STOP;
3349 emission.chain_type = G_TYPE_NONE;
3350 return_value_altered = TRUE;
3352 if (emission.state == EMISSION_STOP)
3354 else if (emission.state == EMISSION_RESTART)
3360 Handler *handler = handler_list;
3362 emission.state = EMISSION_RUN;
3363 handler_ref (handler);
3368 if (handler->after && !handler->block_count && (!handler->detail || handler->detail == detail) &&
3369 handler->sequential_number < max_sequential_handler_number)
3372 g_closure_invoke (handler->closure,
3375 instance_and_params,
3377 if (!accumulate (&emission.ihint, emission_return, &accu, accumulator) &&
3378 emission.state == EMISSION_RUN)
3379 emission.state = EMISSION_STOP;
3381 return_value_altered = TRUE;
3383 tmp = emission.state == EMISSION_RUN ? handler->next : NULL;
3386 tmp = handler->next;
3390 handler_unref_R (signal_id, instance, handler);
3395 if (emission.state == EMISSION_STOP)
3397 else if (emission.state == EMISSION_RESTART)
3403 emission.ihint.run_type = G_SIGNAL_RUN_CLEANUP;
3405 if ((node->flags & G_SIGNAL_RUN_CLEANUP) && class_closure)
3407 gboolean need_unset = FALSE;
3409 emission.state = EMISSION_STOP;
3411 emission.chain_type = G_TYPE_FROM_INSTANCE (instance);
3413 if (node->return_type != G_TYPE_NONE && !accumulator)
3415 g_value_init (&accu, node->return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE);
3418 g_closure_invoke (class_closure,
3419 node->return_type != G_TYPE_NONE ? &accu : NULL,
3421 instance_and_params,
3424 g_value_unset (&accu);
3426 emission.chain_type = G_TYPE_NONE;
3428 if (emission.state == EMISSION_RESTART)
3433 handler_unref_R (signal_id, instance, handler_list);
3435 emission_pop ((node->flags & G_SIGNAL_NO_RECURSE) ? &g_restart_emissions : &g_recursive_emissions, &emission);
3438 g_value_unset (&accu);
3440 TRACE(GOBJECT_SIGNAL_EMIT_END(node->signal_id, detail, instance, G_TYPE_FROM_INSTANCE (instance)));
3442 return return_value_altered;
3446 type_debug_name (GType type)
3450 const char *name = g_type_name (type & ~G_SIGNAL_TYPE_STATIC_SCOPE);
3451 return name ? name : "<unknown>";
3458 * g_signal_accumulator_true_handled:
3459 * @ihint: standard #GSignalAccumulator parameter
3460 * @return_accu: standard #GSignalAccumulator parameter
3461 * @handler_return: standard #GSignalAccumulator parameter
3462 * @dummy: standard #GSignalAccumulator parameter
3464 * A predefined #GSignalAccumulator for signals that return a
3465 * boolean values. The behavior that this accumulator gives is
3466 * that a return of %TRUE stops the signal emission: no further
3467 * callbacks will be invoked, while a return of %FALSE allows
3468 * the emission to continue. The idea here is that a %TRUE return
3469 * indicates that the callback <emphasis>handled</emphasis> the signal,
3470 * and no further handling is needed.
3474 * Returns: standard #GSignalAccumulator result
3477 g_signal_accumulator_true_handled (GSignalInvocationHint *ihint,
3478 GValue *return_accu,
3479 const GValue *handler_return,
3482 gboolean continue_emission;
3483 gboolean signal_handled;
3485 signal_handled = g_value_get_boolean (handler_return);
3486 g_value_set_boolean (return_accu, signal_handled);
3487 continue_emission = !signal_handled;
3489 return continue_emission;
3493 * g_signal_accumulator_first_wins:
3494 * @ihint: standard #GSignalAccumulator parameter
3495 * @return_accu: standard #GSignalAccumulator parameter
3496 * @handler_return: standard #GSignalAccumulator parameter
3497 * @dummy: standard #GSignalAccumulator parameter
3499 * A predefined #GSignalAccumulator for signals intended to be used as a
3500 * hook for application code to provide a particular value. Usually
3501 * only one such value is desired and multiple handlers for the same
3502 * signal don't make much sense (except for the case of the default
3503 * handler defined in the class structure, in which case you will
3504 * usually want the signal connection to override the class handler).
3506 * This accumulator will use the return value from the first signal
3507 * handler that is run as the return value for the signal and not run
3508 * any further handlers (ie: the first handler "wins").
3510 * Returns: standard #GSignalAccumulator result
3515 g_signal_accumulator_first_wins (GSignalInvocationHint *ihint,
3516 GValue *return_accu,
3517 const GValue *handler_return,
3520 g_value_copy (handler_return, return_accu);