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, see <http://www.gnu.org/licenses/>.
17 * this code is based on the original GtkSignal implementation
18 * for the Gtk+ library by Peter Mattis <petm@xcf.berkeley.edu>
31 #include "gtype-private.h"
32 #include "gbsearcharray.h"
33 #include "gvaluecollector.h"
34 #include "gvaluetypes.h"
37 #include "gobject_trace.h"
42 * @short_description: A means for customization of object behaviour
43 * and a general purpose notification mechanism
46 * The basic concept of the signal system is that of the emission
47 * of a signal. Signals are introduced per-type and are identified
48 * through strings. Signals introduced for a parent type are available
49 * in derived types as well, so basically they are a per-type facility
52 * A signal emission mainly involves invocation of a certain set of
53 * callbacks in precisely defined manner. There are two main categories
54 * of such callbacks, per-object ones and user provided ones.
55 * (Although signals can deal with any kind of instantiatable type, I'm
56 * referring to those types as "object types" in the following, simply
57 * because that is the context most users will encounter signals in.)
58 * The per-object callbacks are most often referred to as "object method
59 * handler" or "default (signal) handler", while user provided callbacks are
60 * usually just called "signal handler".
62 * The object method handler is provided at signal creation time (this most
63 * frequently happens at the end of an object class' creation), while user
64 * provided handlers are frequently connected and disconnected to/from a
65 * certain signal on certain object instances.
67 * A signal emission consists of five stages, unless prematurely stopped:
69 * 1. Invocation of the object method handler for %G_SIGNAL_RUN_FIRST signals
71 * 2. Invocation of normal user-provided signal handlers (where the @after
74 * 3. Invocation of the object method handler for %G_SIGNAL_RUN_LAST signals
76 * 4. Invocation of user provided signal handlers (where the @after flag is set)
78 * 5. Invocation of the object method handler for %G_SIGNAL_RUN_CLEANUP signals
80 * The user-provided signal handlers are called in the order they were
83 * All handlers may prematurely stop a signal emission, and any number of
84 * handlers may be connected, disconnected, blocked or unblocked during
87 * There are certain criteria for skipping user handlers in stages 2 and 4
88 * of a signal emission.
90 * First, user handlers may be blocked. Blocked handlers are omitted during
91 * callback invocation, to return from the blocked state, a handler has to
92 * get unblocked exactly the same amount of times it has been blocked before.
94 * Second, upon emission of a %G_SIGNAL_DETAILED signal, an additional
95 * @detail argument passed in to g_signal_emit() has to match the detail
96 * argument of the signal handler currently subject to invocation.
97 * Specification of no detail argument for signal handlers (omission of the
98 * detail part of the signal specification upon connection) serves as a
99 * wildcard and matches any detail argument passed in to emission.
103 #define REPORT_BUG "please report occurrence circumstances to gtk-devel-list@gnome.org"
105 /* --- typedefs --- */
106 typedef struct _SignalNode SignalNode;
107 typedef struct _SignalKey SignalKey;
108 typedef struct _Emission Emission;
109 typedef struct _Handler Handler;
110 typedef struct _HandlerList HandlerList;
111 typedef struct _HandlerMatch HandlerMatch;
121 /* --- prototypes --- */
122 static inline guint signal_id_lookup (GQuark quark,
124 static void signal_destroy_R (SignalNode *signal_node);
125 static inline HandlerList* handler_list_ensure (guint signal_id,
127 static inline HandlerList* handler_list_lookup (guint signal_id,
129 static inline Handler* handler_new (gboolean after);
130 static void handler_insert (guint signal_id,
133 static Handler* handler_lookup (gpointer instance,
137 static inline HandlerMatch* handler_match_prepend (HandlerMatch *list,
140 static inline HandlerMatch* handler_match_free1_R (HandlerMatch *node,
142 static HandlerMatch* handlers_find (gpointer instance,
143 GSignalMatchType mask,
149 gboolean one_and_only);
150 static inline void handler_ref (Handler *handler);
151 static inline void handler_unref_R (guint signal_id,
154 static gint handler_lists_cmp (gconstpointer node1,
155 gconstpointer node2);
156 static inline void emission_push (Emission *emission);
157 static inline void emission_pop (Emission *emission);
158 static inline Emission* emission_find (guint signal_id,
161 static gint class_closures_cmp (gconstpointer node1,
162 gconstpointer node2);
163 static gint signal_key_cmp (gconstpointer node1,
164 gconstpointer node2);
165 static gboolean signal_emit_unlocked_R (SignalNode *node,
168 GValue *return_value,
169 const GValue *instance_and_params);
170 static void add_invalid_closure_notify (Handler *handler,
172 static void remove_invalid_closure_notify (Handler *handler,
174 static void invalid_closure_notify (gpointer data,
176 static const gchar * type_debug_name (GType type);
177 static void node_check_deprecated (const SignalNode *node);
178 static void node_update_single_va_closure (SignalNode *node);
181 /* --- structures --- */
184 GSignalAccumulator func;
192 #define SIGNAL_HOOK(hook) ((SignalHook*) (hook))
196 /* permanent portion */
202 /* reinitializable portion */
205 guint single_va_closure_is_valid : 1;
206 guint single_va_closure_is_after : 1;
207 GType *param_types; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
208 GType return_type; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
209 GBSearchArray *class_closure_bsa;
210 SignalAccumulator *accumulator;
211 GSignalCMarshaller c_marshaller;
212 GSignalCVaMarshaller va_marshaller;
213 GHookList *emission_hooks;
215 GClosure *single_va_closure;
218 #define SINGLE_VA_CLOSURE_EMPTY_MAGIC GINT_TO_POINTER(1) /* indicates single_va_closure is valid but empty */
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)
254 guint has_invalid_closure_notify : 1;
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_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 (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,
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 (closure ? (handler->closure == closure) : (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 G_REAL_CLOSURE (handler->closure)->meta_marshal == NULL &&
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 G_REAL_CLOSURE (handler->closure)->meta_marshal == NULL &&
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;
573 handler->has_invalid_closure_notify = 0;
579 handler_ref (Handler *handler)
581 g_return_if_fail (handler->ref_count > 0);
583 handler->ref_count++;
587 handler_unref_R (guint signal_id,
591 g_return_if_fail (handler->ref_count > 0);
593 handler->ref_count--;
595 if (G_UNLIKELY (handler->ref_count == 0))
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 node_update_single_va_closure (SignalNode *node)
691 GClosure *closure = NULL;
692 gboolean is_after = FALSE;
694 /* Fast path single-handler without boxing the arguments in GValues */
695 if (G_TYPE_IS_OBJECT (node->itype) &&
696 (node->flags & (G_SIGNAL_MUST_COLLECT)) == 0 &&
697 (node->emission_hooks == NULL || node->emission_hooks->hooks == NULL))
699 GSignalFlags run_type;
701 GBSearchArray *bsa = node->class_closure_bsa;
703 if (bsa == NULL || bsa->n_nodes == 0)
704 closure = SINGLE_VA_CLOSURE_EMPTY_MAGIC;
705 else if (bsa->n_nodes == 1)
707 /* Look for default class closure (can't support non-default as it
708 chains up using GValues */
709 cc = g_bsearch_array_get_nth (bsa, &g_class_closure_bconfig, 0);
710 if (cc->instance_type == 0)
712 run_type = node->flags & (G_SIGNAL_RUN_FIRST|G_SIGNAL_RUN_LAST|G_SIGNAL_RUN_CLEANUP);
713 /* Only support *one* of run-first or run-last, not multiple or cleanup */
714 if (run_type == G_SIGNAL_RUN_FIRST ||
715 run_type == G_SIGNAL_RUN_LAST)
717 closure = cc->closure;
718 is_after = (run_type == G_SIGNAL_RUN_LAST);
724 node->single_va_closure_is_valid = TRUE;
725 node->single_va_closure = closure;
726 node->single_va_closure_is_after = is_after;
730 emission_push (Emission *emission)
732 emission->next = g_emissions;
733 g_emissions = emission;
737 emission_pop (Emission *emission)
739 Emission *node, *last = NULL;
741 for (node = g_emissions; node; last = node, node = last->next)
742 if (node == emission)
745 last->next = node->next;
747 g_emissions = node->next;
750 g_assert_not_reached ();
753 static inline Emission*
754 emission_find (guint signal_id,
760 for (emission = g_emissions; emission; emission = emission->next)
761 if (emission->instance == instance &&
762 emission->ihint.signal_id == signal_id &&
763 emission->ihint.detail == detail)
768 static inline Emission*
769 emission_find_innermost (gpointer instance)
773 for (emission = g_emissions; emission; emission = emission->next)
774 if (emission->instance == instance)
781 signal_key_cmp (gconstpointer node1,
784 const SignalKey *key1 = node1, *key2 = node2;
786 if (key1->itype == key2->itype)
787 return G_BSEARCH_ARRAY_CMP (key1->quark, key2->quark);
789 return G_BSEARCH_ARRAY_CMP (key1->itype, key2->itype);
793 _g_signal_init (void)
796 if (!g_n_signal_nodes)
798 /* setup handler list binary searchable array hash table (in german, that'd be one word ;) */
799 g_handler_list_bsa_ht = g_hash_table_new (g_direct_hash, NULL);
800 g_signal_key_bsa = g_bsearch_array_create (&g_signal_key_bconfig);
802 /* invalid (0) signal_id */
803 g_n_signal_nodes = 1;
804 g_signal_nodes = g_renew (SignalNode*, g_signal_nodes, g_n_signal_nodes);
805 g_signal_nodes[0] = NULL;
811 _g_signals_destroy (GType itype)
816 for (i = 1; i < g_n_signal_nodes; i++)
818 SignalNode *node = g_signal_nodes[i];
820 if (node->itype == itype)
823 g_warning (G_STRLOC ": signal \"%s\" of type '%s' already destroyed",
825 type_debug_name (node->itype));
827 signal_destroy_R (node);
834 * g_signal_stop_emission:
835 * @instance: (type GObject.Object): the object whose signal handlers you wish to stop.
836 * @signal_id: the signal identifier, as returned by g_signal_lookup().
837 * @detail: the detail which the signal was emitted with.
839 * Stops a signal's current emission.
841 * This will prevent the default method from running, if the signal was
842 * %G_SIGNAL_RUN_LAST and you connected normally (i.e. without the "after"
845 * Prints a warning if used on a signal which isn't being emitted.
848 g_signal_stop_emission (gpointer instance,
854 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
855 g_return_if_fail (signal_id > 0);
858 node = LOOKUP_SIGNAL_NODE (signal_id);
859 if (node && detail && !(node->flags & G_SIGNAL_DETAILED))
861 g_warning ("%s: signal id '%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
865 if (node && g_type_is_a (G_TYPE_FROM_INSTANCE (instance), node->itype))
867 Emission *emission = emission_find (signal_id, detail, instance);
871 if (emission->state == EMISSION_HOOK)
872 g_warning (G_STRLOC ": emission of signal \"%s\" for instance '%p' cannot be stopped from emission hook",
873 node->name, instance);
874 else if (emission->state == EMISSION_RUN)
875 emission->state = EMISSION_STOP;
878 g_warning (G_STRLOC ": no emission of signal \"%s\" to stop for instance '%p'",
879 node->name, instance);
882 g_warning ("%s: signal id '%u' is invalid for instance '%p'", G_STRLOC, signal_id, instance);
887 signal_finalize_hook (GHookList *hook_list,
890 GDestroyNotify destroy = hook->destroy;
894 hook->destroy = NULL;
896 destroy (hook->data);
902 * g_signal_add_emission_hook:
903 * @signal_id: the signal identifier, as returned by g_signal_lookup().
904 * @detail: the detail on which to call the hook.
905 * @hook_func: a #GSignalEmissionHook function.
906 * @hook_data: user data for @hook_func.
907 * @data_destroy: a #GDestroyNotify for @hook_data.
909 * Adds an emission hook for a signal, which will get called for any emission
910 * of that signal, independent of the instance. This is possible only
911 * for signals which don't have #G_SIGNAL_NO_HOOKS flag set.
913 * Returns: the hook id, for later use with g_signal_remove_emission_hook().
916 g_signal_add_emission_hook (guint signal_id,
918 GSignalEmissionHook hook_func,
920 GDestroyNotify data_destroy)
922 static gulong seq_hook_id = 1;
925 SignalHook *signal_hook;
927 g_return_val_if_fail (signal_id > 0, 0);
928 g_return_val_if_fail (hook_func != NULL, 0);
931 node = LOOKUP_SIGNAL_NODE (signal_id);
932 if (!node || node->destroyed)
934 g_warning ("%s: invalid signal id '%u'", G_STRLOC, signal_id);
938 if (node->flags & G_SIGNAL_NO_HOOKS)
940 g_warning ("%s: signal id '%u' does not support emission hooks (G_SIGNAL_NO_HOOKS flag set)", G_STRLOC, signal_id);
944 if (detail && !(node->flags & G_SIGNAL_DETAILED))
946 g_warning ("%s: signal id '%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
950 node->single_va_closure_is_valid = FALSE;
951 if (!node->emission_hooks)
953 node->emission_hooks = g_new (GHookList, 1);
954 g_hook_list_init (node->emission_hooks, sizeof (SignalHook));
955 node->emission_hooks->finalize_hook = signal_finalize_hook;
958 node_check_deprecated (node);
960 hook = g_hook_alloc (node->emission_hooks);
961 hook->data = hook_data;
962 hook->func = (gpointer) hook_func;
963 hook->destroy = data_destroy;
964 signal_hook = SIGNAL_HOOK (hook);
965 signal_hook->detail = detail;
966 node->emission_hooks->seq_id = seq_hook_id;
967 g_hook_append (node->emission_hooks, hook);
968 seq_hook_id = node->emission_hooks->seq_id;
972 return hook->hook_id;
976 * g_signal_remove_emission_hook:
977 * @signal_id: the id of the signal
978 * @hook_id: the id of the emission hook, as returned by
979 * g_signal_add_emission_hook()
981 * Deletes an emission hook.
984 g_signal_remove_emission_hook (guint signal_id,
989 g_return_if_fail (signal_id > 0);
990 g_return_if_fail (hook_id > 0);
993 node = LOOKUP_SIGNAL_NODE (signal_id);
994 if (!node || node->destroyed)
996 g_warning ("%s: invalid signal id '%u'", G_STRLOC, signal_id);
999 else if (!node->emission_hooks || !g_hook_destroy (node->emission_hooks, hook_id))
1000 g_warning ("%s: signal \"%s\" had no hook (%lu) to remove", G_STRLOC, node->name, hook_id);
1002 node->single_va_closure_is_valid = FALSE;
1009 signal_parse_name (const gchar *name,
1012 gboolean force_quark)
1014 const gchar *colon = strchr (name, ':');
1019 signal_id = signal_id_lookup (g_quark_try_string (name), itype);
1020 if (signal_id && detail_p)
1023 else if (colon[1] == ':')
1026 guint l = colon - name;
1030 memcpy (buffer, name, l);
1032 signal_id = signal_id_lookup (g_quark_try_string (buffer), itype);
1036 gchar *signal = g_new (gchar, l + 1);
1038 memcpy (signal, name, l);
1040 signal_id = signal_id_lookup (g_quark_try_string (signal), itype);
1044 if (signal_id && detail_p)
1045 *detail_p = colon[2] ? (force_quark ? g_quark_from_string : g_quark_try_string) (colon + 2) : 0;
1053 * g_signal_parse_name:
1054 * @detailed_signal: a string of the form "signal-name::detail".
1055 * @itype: The interface/instance type that introduced "signal-name".
1056 * @signal_id_p: (out): Location to store the signal id.
1057 * @detail_p: (out): Location to store the detail quark.
1058 * @force_detail_quark: %TRUE forces creation of a #GQuark for the detail.
1060 * Internal function to parse a signal name into its @signal_id
1061 * and @detail quark.
1063 * Returns: Whether the signal name could successfully be parsed and @signal_id_p and @detail_p contain valid return values.
1066 g_signal_parse_name (const gchar *detailed_signal,
1070 gboolean force_detail_quark)
1076 g_return_val_if_fail (detailed_signal != NULL, FALSE);
1077 g_return_val_if_fail (G_TYPE_IS_INSTANTIATABLE (itype) || G_TYPE_IS_INTERFACE (itype), FALSE);
1080 signal_id = signal_parse_name (detailed_signal, itype, &detail, force_detail_quark);
1083 node = signal_id ? LOOKUP_SIGNAL_NODE (signal_id) : NULL;
1084 if (!node || node->destroyed ||
1085 (detail && !(node->flags & G_SIGNAL_DETAILED)))
1089 *signal_id_p = signal_id;
1097 * g_signal_stop_emission_by_name:
1098 * @instance: (type GObject.Object): the object whose signal handlers you wish to stop.
1099 * @detailed_signal: a string of the form "signal-name::detail".
1101 * Stops a signal's current emission.
1103 * This is just like g_signal_stop_emission() except it will look up the
1104 * signal id for you.
1107 g_signal_stop_emission_by_name (gpointer instance,
1108 const gchar *detailed_signal)
1114 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
1115 g_return_if_fail (detailed_signal != NULL);
1118 itype = G_TYPE_FROM_INSTANCE (instance);
1119 signal_id = signal_parse_name (detailed_signal, itype, &detail, TRUE);
1122 SignalNode *node = LOOKUP_SIGNAL_NODE (signal_id);
1124 if (detail && !(node->flags & G_SIGNAL_DETAILED))
1125 g_warning ("%s: signal '%s' does not support details", G_STRLOC, detailed_signal);
1126 else if (!g_type_is_a (itype, node->itype))
1127 g_warning ("%s: signal '%s' is invalid for instance '%p' of type '%s'",
1128 G_STRLOC, detailed_signal, instance, g_type_name (itype));
1131 Emission *emission = emission_find (signal_id, detail, instance);
1135 if (emission->state == EMISSION_HOOK)
1136 g_warning (G_STRLOC ": emission of signal \"%s\" for instance '%p' cannot be stopped from emission hook",
1137 node->name, instance);
1138 else if (emission->state == EMISSION_RUN)
1139 emission->state = EMISSION_STOP;
1142 g_warning (G_STRLOC ": no emission of signal \"%s\" to stop for instance '%p'",
1143 node->name, instance);
1147 g_warning ("%s: signal '%s' is invalid for instance '%p' of type '%s'",
1148 G_STRLOC, detailed_signal, instance, g_type_name (itype));
1154 * @name: the signal's name.
1155 * @itype: the type that the signal operates on.
1157 * Given the name of the signal and the type of object it connects to, gets
1158 * the signal's identifying integer. Emitting the signal by number is
1159 * somewhat faster than using the name each time.
1161 * Also tries the ancestors of the given type.
1163 * See g_signal_new() for details on allowed signal names.
1165 * Returns: the signal's identifying number, or 0 if no signal was found.
1168 g_signal_lookup (const gchar *name,
1172 g_return_val_if_fail (name != NULL, 0);
1173 g_return_val_if_fail (G_TYPE_IS_INSTANTIATABLE (itype) || G_TYPE_IS_INTERFACE (itype), 0);
1176 signal_id = signal_id_lookup (g_quark_try_string (name), itype);
1180 /* give elaborate warnings */
1181 if (!g_type_name (itype))
1182 g_warning (G_STRLOC ": unable to lookup signal \"%s\" for invalid type id '%"G_GSIZE_FORMAT"'",
1184 else if (!G_TYPE_IS_INSTANTIATABLE (itype))
1185 g_warning (G_STRLOC ": unable to lookup signal \"%s\" for non instantiatable type '%s'",
1186 name, g_type_name (itype));
1187 else if (!g_type_class_peek (itype))
1188 g_warning (G_STRLOC ": unable to lookup signal \"%s\" of unloaded type '%s'",
1189 name, g_type_name (itype));
1196 * g_signal_list_ids:
1197 * @itype: Instance or interface type.
1198 * @n_ids: Location to store the number of signal ids for @itype.
1200 * Lists the signals by id that a certain instance or interface type
1201 * created. Further information about the signals can be acquired through
1204 * Returns: (array length=n_ids): Newly allocated array of signal IDs.
1207 g_signal_list_ids (GType itype,
1215 g_return_val_if_fail (G_TYPE_IS_INSTANTIATABLE (itype) || G_TYPE_IS_INTERFACE (itype), NULL);
1216 g_return_val_if_fail (n_ids != NULL, NULL);
1219 keys = g_bsearch_array_get_nth (g_signal_key_bsa, &g_signal_key_bconfig, 0);
1220 n_nodes = g_bsearch_array_get_n_nodes (g_signal_key_bsa);
1221 result = g_array_new (FALSE, FALSE, sizeof (guint));
1223 for (i = 0; i < n_nodes; i++)
1224 if (keys[i].itype == itype)
1226 const gchar *name = g_quark_to_string (keys[i].quark);
1228 /* Signal names with "_" in them are aliases to the same
1229 * name with "-" instead of "_".
1231 if (!strchr (name, '_'))
1232 g_array_append_val (result, keys[i].signal_id);
1234 *n_ids = result->len;
1238 /* give elaborate warnings */
1239 if (!g_type_name (itype))
1240 g_warning (G_STRLOC ": unable to list signals for invalid type id '%"G_GSIZE_FORMAT"'",
1242 else if (!G_TYPE_IS_INSTANTIATABLE (itype) && !G_TYPE_IS_INTERFACE (itype))
1243 g_warning (G_STRLOC ": unable to list signals of non instantiatable type '%s'",
1244 g_type_name (itype));
1245 else if (!g_type_class_peek (itype) && !G_TYPE_IS_INTERFACE (itype))
1246 g_warning (G_STRLOC ": unable to list signals of unloaded type '%s'",
1247 g_type_name (itype));
1250 return (guint*) g_array_free (result, FALSE);
1255 * @signal_id: the signal's identifying number.
1257 * Given the signal's identifier, finds its name.
1259 * Two different signals may have the same name, if they have differing types.
1261 * Returns: the signal name, or %NULL if the signal number was invalid.
1264 g_signal_name (guint signal_id)
1270 node = LOOKUP_SIGNAL_NODE (signal_id);
1271 name = node ? node->name : NULL;
1274 return (char*) name;
1279 * @signal_id: The signal id of the signal to query information for.
1280 * @query: (out caller-allocates): A user provided structure that is
1281 * filled in with constant values upon success.
1283 * Queries the signal system for in-depth information about a
1284 * specific signal. This function will fill in a user-provided
1285 * structure to hold signal-specific information. If an invalid
1286 * signal id is passed in, the @signal_id member of the #GSignalQuery
1287 * is 0. All members filled into the #GSignalQuery structure should
1288 * be considered constant and have to be left untouched.
1291 g_signal_query (guint signal_id,
1292 GSignalQuery *query)
1296 g_return_if_fail (query != NULL);
1299 node = LOOKUP_SIGNAL_NODE (signal_id);
1300 if (!node || node->destroyed)
1301 query->signal_id = 0;
1304 query->signal_id = node->signal_id;
1305 query->signal_name = node->name;
1306 query->itype = node->itype;
1307 query->signal_flags = node->flags;
1308 query->return_type = node->return_type;
1309 query->n_params = node->n_params;
1310 query->param_types = node->param_types;
1317 * @signal_name: the name for the signal
1318 * @itype: the type this signal pertains to. It will also pertain to
1319 * types which are derived from this type.
1320 * @signal_flags: a combination of #GSignalFlags specifying detail of when
1321 * the default handler is to be invoked. You should at least specify
1322 * %G_SIGNAL_RUN_FIRST or %G_SIGNAL_RUN_LAST.
1323 * @class_offset: The offset of the function pointer in the class structure
1324 * for this type. Used to invoke a class method generically. Pass 0 to
1325 * not associate a class method slot with this signal.
1326 * @accumulator: the accumulator for this signal; may be %NULL.
1327 * @accu_data: user data for the @accumulator.
1328 * @c_marshaller: (allow-none): the function to translate arrays of parameter
1329 * values to signal emissions into C language callback invocations or %NULL.
1330 * @return_type: the type of return value, or #G_TYPE_NONE for a signal
1331 * without a return value.
1332 * @n_params: the number of parameter types to follow.
1333 * @...: a list of types, one for each parameter.
1335 * Creates a new signal. (This is usually done in the class initializer.)
1337 * A signal name consists of segments consisting of ASCII letters and
1338 * digits, separated by either the '-' or '_' character. The first
1339 * character of a signal name must be a letter. Names which violate these
1340 * rules lead to undefined behaviour of the GSignal system.
1342 * When registering a signal and looking up a signal, either separator can
1343 * be used, but they cannot be mixed.
1345 * If 0 is used for @class_offset subclasses cannot override the class handler
1346 * in their class_init method by doing super_class->signal_handler = my_signal_handler.
1347 * Instead they will have to use g_signal_override_class_handler().
1349 * If c_marshaller is %NULL, g_cclosure_marshal_generic() will be used as
1350 * the marshaller for this signal.
1352 * Returns: the signal id
1355 g_signal_new (const gchar *signal_name,
1357 GSignalFlags signal_flags,
1359 GSignalAccumulator accumulator,
1361 GSignalCMarshaller c_marshaller,
1369 g_return_val_if_fail (signal_name != NULL, 0);
1371 va_start (args, n_params);
1373 signal_id = g_signal_new_valist (signal_name, itype, signal_flags,
1374 class_offset ? g_signal_type_cclosure_new (itype, class_offset) : NULL,
1375 accumulator, accu_data, c_marshaller,
1376 return_type, n_params, args);
1384 * g_signal_new_class_handler:
1385 * @signal_name: the name for the signal
1386 * @itype: the type this signal pertains to. It will also pertain to
1387 * types which are derived from this type.
1388 * @signal_flags: a combination of #GSignalFlags specifying detail of when
1389 * the default handler is to be invoked. You should at least specify
1390 * %G_SIGNAL_RUN_FIRST or %G_SIGNAL_RUN_LAST.
1391 * @class_handler: a #GCallback which acts as class implementation of
1392 * this signal. Used to invoke a class method generically. Pass %NULL to
1393 * not associate a class method with this signal.
1394 * @accumulator: the accumulator for this signal; may be %NULL.
1395 * @accu_data: user data for the @accumulator.
1396 * @c_marshaller: (allow-none): the function to translate arrays of parameter
1397 * values to signal emissions into C language callback invocations or %NULL.
1398 * @return_type: the type of return value, or #G_TYPE_NONE for a signal
1399 * without a return value.
1400 * @n_params: the number of parameter types to follow.
1401 * @...: a list of types, one for each parameter.
1403 * Creates a new signal. (This is usually done in the class initializer.)
1405 * This is a variant of g_signal_new() that takes a C callback instead
1406 * off a class offset for the signal's class handler. This function
1407 * doesn't need a function pointer exposed in the class structure of
1408 * an object definition, instead the function pointer is passed
1409 * directly and can be overriden by derived classes with
1410 * g_signal_override_class_closure() or
1411 * g_signal_override_class_handler()and chained to with
1412 * g_signal_chain_from_overridden() or
1413 * g_signal_chain_from_overridden_handler().
1415 * See g_signal_new() for information about signal names.
1417 * If c_marshaller is %NULL, g_cclosure_marshal_generic() will be used as
1418 * the marshaller for this signal.
1420 * Returns: the signal id
1425 g_signal_new_class_handler (const gchar *signal_name,
1427 GSignalFlags signal_flags,
1428 GCallback class_handler,
1429 GSignalAccumulator accumulator,
1431 GSignalCMarshaller c_marshaller,
1439 g_return_val_if_fail (signal_name != NULL, 0);
1441 va_start (args, n_params);
1443 signal_id = g_signal_new_valist (signal_name, itype, signal_flags,
1444 class_handler ? g_cclosure_new (class_handler, NULL, NULL) : NULL,
1445 accumulator, accu_data, c_marshaller,
1446 return_type, n_params, args);
1453 static inline ClassClosure*
1454 signal_find_class_closure (SignalNode *node,
1457 GBSearchArray *bsa = node->class_closure_bsa;
1464 /* cc->instance_type is 0 for default closure */
1466 key.instance_type = itype;
1467 cc = g_bsearch_array_lookup (bsa, &g_class_closure_bconfig, &key);
1468 while (!cc && key.instance_type)
1470 key.instance_type = g_type_parent (key.instance_type);
1471 cc = g_bsearch_array_lookup (bsa, &g_class_closure_bconfig, &key);
1479 static inline GClosure*
1480 signal_lookup_closure (SignalNode *node,
1481 GTypeInstance *instance)
1485 if (node->class_closure_bsa && g_bsearch_array_get_n_nodes (node->class_closure_bsa) == 1)
1487 cc = g_bsearch_array_get_nth (node->class_closure_bsa, &g_class_closure_bconfig, 0);
1488 if (cc && cc->instance_type == 0) /* check for default closure */
1491 cc = signal_find_class_closure (node, G_TYPE_FROM_INSTANCE (instance));
1492 return cc ? cc->closure : NULL;
1496 signal_add_class_closure (SignalNode *node,
1502 node->single_va_closure_is_valid = FALSE;
1504 if (!node->class_closure_bsa)
1505 node->class_closure_bsa = g_bsearch_array_create (&g_class_closure_bconfig);
1506 key.instance_type = itype;
1507 key.closure = g_closure_ref (closure);
1508 node->class_closure_bsa = g_bsearch_array_insert (node->class_closure_bsa,
1509 &g_class_closure_bconfig,
1511 g_closure_sink (closure);
1512 if (node->c_marshaller && closure && G_CLOSURE_NEEDS_MARSHAL (closure))
1514 g_closure_set_marshal (closure, node->c_marshaller);
1515 if (node->va_marshaller)
1516 _g_closure_set_va_marshal (closure, node->va_marshaller);
1522 * @signal_name: the name for the signal
1523 * @itype: the type this signal pertains to. It will also pertain to
1524 * types which are derived from this type
1525 * @signal_flags: a combination of #GSignalFlags specifying detail of when
1526 * the default handler is to be invoked. You should at least specify
1527 * %G_SIGNAL_RUN_FIRST or %G_SIGNAL_RUN_LAST
1528 * @class_closure: (allow-none): The closure to invoke on signal emission;
1530 * @accumulator: (allow-none): the accumulator for this signal; may be %NULL
1531 * @accu_data: user data for the @accumulator
1532 * @c_marshaller: (allow-none): the function to translate arrays of
1533 * parameter values to signal emissions into C language callback
1534 * invocations or %NULL
1535 * @return_type: the type of return value, or #G_TYPE_NONE for a signal
1536 * without a return value
1537 * @n_params: the length of @param_types
1538 * @param_types: (array length=n_params): an array of types, one for
1541 * Creates a new signal. (This is usually done in the class initializer.)
1543 * See g_signal_new() for details on allowed signal names.
1545 * If c_marshaller is %NULL, g_cclosure_marshal_generic() will be used as
1546 * the marshaller for this signal.
1548 * Returns: the signal id
1551 g_signal_newv (const gchar *signal_name,
1553 GSignalFlags signal_flags,
1554 GClosure *class_closure,
1555 GSignalAccumulator accumulator,
1557 GSignalCMarshaller c_marshaller,
1565 GSignalCMarshaller builtin_c_marshaller;
1566 GSignalCVaMarshaller va_marshaller;
1568 g_return_val_if_fail (signal_name != NULL, 0);
1569 g_return_val_if_fail (G_TYPE_IS_INSTANTIATABLE (itype) || G_TYPE_IS_INTERFACE (itype), 0);
1571 g_return_val_if_fail (param_types != NULL, 0);
1572 g_return_val_if_fail ((return_type & G_SIGNAL_TYPE_STATIC_SCOPE) == 0, 0);
1573 if (return_type == (G_TYPE_NONE & ~G_SIGNAL_TYPE_STATIC_SCOPE))
1574 g_return_val_if_fail (accumulator == NULL, 0);
1576 g_return_val_if_fail (accu_data == NULL, 0);
1578 name = g_strdup (signal_name);
1579 g_strdelimit (name, G_STR_DELIMITERS ":^", '_'); /* FIXME do character checks like for types */
1583 signal_id = signal_id_lookup (g_quark_try_string (name), itype);
1584 node = LOOKUP_SIGNAL_NODE (signal_id);
1585 if (node && !node->destroyed)
1587 g_warning (G_STRLOC ": signal \"%s\" already exists in the '%s' %s",
1589 type_debug_name (node->itype),
1590 G_TYPE_IS_INTERFACE (node->itype) ? "interface" : "class ancestry");
1595 if (node && node->itype != itype)
1597 g_warning (G_STRLOC ": signal \"%s\" for type '%s' was previously created for type '%s'",
1599 type_debug_name (itype),
1600 type_debug_name (node->itype));
1605 for (i = 0; i < n_params; i++)
1606 if (!G_TYPE_IS_VALUE (param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE))
1608 g_warning (G_STRLOC ": parameter %d of type '%s' for signal \"%s::%s\" is not a value type",
1609 i + 1, type_debug_name (param_types[i]), type_debug_name (itype), name);
1614 if (return_type != G_TYPE_NONE && !G_TYPE_IS_VALUE (return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE))
1616 g_warning (G_STRLOC ": return value of type '%s' for signal \"%s::%s\" is not a value type",
1617 type_debug_name (return_type), type_debug_name (itype), name);
1622 if (return_type != G_TYPE_NONE &&
1623 (signal_flags & (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST | G_SIGNAL_RUN_CLEANUP)) == G_SIGNAL_RUN_FIRST)
1625 g_warning (G_STRLOC ": signal \"%s::%s\" has return type '%s' and is only G_SIGNAL_RUN_FIRST",
1626 type_debug_name (itype), name, type_debug_name (return_type));
1632 /* setup permanent portion of signal node */
1637 signal_id = g_n_signal_nodes++;
1638 node = g_new (SignalNode, 1);
1639 node->signal_id = signal_id;
1640 g_signal_nodes = g_renew (SignalNode*, g_signal_nodes, g_n_signal_nodes);
1641 g_signal_nodes[signal_id] = node;
1642 node->itype = itype;
1645 key.quark = g_quark_from_string (node->name);
1646 key.signal_id = signal_id;
1647 g_signal_key_bsa = g_bsearch_array_insert (g_signal_key_bsa, &g_signal_key_bconfig, &key);
1648 g_strdelimit (name, "_", '-');
1649 node->name = g_intern_string (name);
1650 key.quark = g_quark_from_string (name);
1651 g_signal_key_bsa = g_bsearch_array_insert (g_signal_key_bsa, &g_signal_key_bconfig, &key);
1653 TRACE(GOBJECT_SIGNAL_NEW(signal_id, name, itype));
1655 node->destroyed = FALSE;
1657 /* setup reinitializable portion */
1658 node->single_va_closure_is_valid = FALSE;
1659 node->flags = signal_flags & G_SIGNAL_FLAGS_MASK;
1660 node->n_params = n_params;
1661 node->param_types = g_memdup (param_types, sizeof (GType) * n_params);
1662 node->return_type = return_type;
1663 node->class_closure_bsa = NULL;
1666 node->accumulator = g_new (SignalAccumulator, 1);
1667 node->accumulator->func = accumulator;
1668 node->accumulator->data = accu_data;
1671 node->accumulator = NULL;
1673 builtin_c_marshaller = NULL;
1674 va_marshaller = NULL;
1676 /* Pick up built-in va marshallers for standard types, and
1677 instead of generic marshaller if no marshaller specified */
1678 if (n_params == 0 && return_type == G_TYPE_NONE)
1680 builtin_c_marshaller = g_cclosure_marshal_VOID__VOID;
1681 va_marshaller = g_cclosure_marshal_VOID__VOIDv;
1683 else if (n_params == 1 && return_type == G_TYPE_NONE)
1685 #define ADD_CHECK(__type__) \
1686 else if (g_type_is_a (param_types[0] & ~G_SIGNAL_TYPE_STATIC_SCOPE, G_TYPE_ ##__type__)) \
1688 builtin_c_marshaller = g_cclosure_marshal_VOID__ ## __type__; \
1689 va_marshaller = g_cclosure_marshal_VOID__ ## __type__ ##v; \
1712 if (c_marshaller == NULL)
1714 if (builtin_c_marshaller)
1715 c_marshaller = builtin_c_marshaller;
1718 c_marshaller = g_cclosure_marshal_generic;
1719 va_marshaller = g_cclosure_marshal_generic_va;
1723 node->c_marshaller = c_marshaller;
1724 node->va_marshaller = va_marshaller;
1725 node->emission_hooks = NULL;
1727 signal_add_class_closure (node, 0, class_closure);
1737 * g_signal_set_va_marshaller:
1738 * @signal_id: the signal id
1739 * @instance_type: the instance type on which to set the marshaller.
1740 * @va_marshaller: the marshaller to set.
1742 * Change the #GSignalCVaMarshaller used for a given signal. This is a
1743 * specialised form of the marshaller that can often be used for the
1744 * common case of a single connected signal handler and avoids the
1745 * overhead of #GValue. Its use is optional.
1750 g_signal_set_va_marshaller (guint signal_id,
1751 GType instance_type,
1752 GSignalCVaMarshaller va_marshaller)
1756 g_return_if_fail (signal_id > 0);
1757 g_return_if_fail (va_marshaller != NULL);
1760 node = LOOKUP_SIGNAL_NODE (signal_id);
1763 node->va_marshaller = va_marshaller;
1764 if (node->class_closure_bsa)
1766 ClassClosure *cc = g_bsearch_array_get_nth (node->class_closure_bsa, &g_class_closure_bconfig, 0);
1767 if (cc->closure->marshal == node->c_marshaller)
1768 _g_closure_set_va_marshal (cc->closure, va_marshaller);
1771 node->single_va_closure_is_valid = FALSE;
1779 * g_signal_new_valist:
1780 * @signal_name: the name for the signal
1781 * @itype: the type this signal pertains to. It will also pertain to
1782 * types which are derived from this type.
1783 * @signal_flags: a combination of #GSignalFlags specifying detail of when
1784 * the default handler is to be invoked. You should at least specify
1785 * %G_SIGNAL_RUN_FIRST or %G_SIGNAL_RUN_LAST.
1786 * @class_closure: The closure to invoke on signal emission; may be %NULL.
1787 * @accumulator: the accumulator for this signal; may be %NULL.
1788 * @accu_data: user data for the @accumulator.
1789 * @c_marshaller: (allow-none): the function to translate arrays of parameter
1790 * values to signal emissions into C language callback invocations or %NULL.
1791 * @return_type: the type of return value, or #G_TYPE_NONE for a signal
1792 * without a return value.
1793 * @n_params: the number of parameter types in @args.
1794 * @args: va_list of #GType, one for each parameter.
1796 * Creates a new signal. (This is usually done in the class initializer.)
1798 * See g_signal_new() for details on allowed signal names.
1800 * If c_marshaller is %NULL, g_cclosure_marshal_generic() will be used as
1801 * the marshaller for this signal.
1803 * Returns: the signal id
1806 g_signal_new_valist (const gchar *signal_name,
1808 GSignalFlags signal_flags,
1809 GClosure *class_closure,
1810 GSignalAccumulator accumulator,
1812 GSignalCMarshaller c_marshaller,
1823 param_types = g_new (GType, n_params);
1825 for (i = 0; i < n_params; i++)
1826 param_types[i] = va_arg (args, GType);
1831 signal_id = g_signal_newv (signal_name, itype, signal_flags,
1832 class_closure, accumulator, accu_data, c_marshaller,
1833 return_type, n_params, param_types);
1834 g_free (param_types);
1840 signal_destroy_R (SignalNode *signal_node)
1842 SignalNode node = *signal_node;
1844 signal_node->destroyed = TRUE;
1846 /* reentrancy caution, zero out real contents first */
1847 signal_node->single_va_closure_is_valid = FALSE;
1848 signal_node->n_params = 0;
1849 signal_node->param_types = NULL;
1850 signal_node->return_type = 0;
1851 signal_node->class_closure_bsa = NULL;
1852 signal_node->accumulator = NULL;
1853 signal_node->c_marshaller = NULL;
1854 signal_node->va_marshaller = NULL;
1855 signal_node->emission_hooks = NULL;
1857 #ifdef G_ENABLE_DEBUG
1858 /* check current emissions */
1862 for (emission = g_emissions; emission; emission = emission->next)
1863 if (emission->ihint.signal_id == node.signal_id)
1864 g_critical (G_STRLOC ": signal \"%s\" being destroyed is currently in emission (instance '%p')",
1865 node.name, emission->instance);
1869 /* free contents that need to
1872 g_free (node.param_types);
1873 if (node.class_closure_bsa)
1877 for (i = 0; i < node.class_closure_bsa->n_nodes; i++)
1879 ClassClosure *cc = g_bsearch_array_get_nth (node.class_closure_bsa, &g_class_closure_bconfig, i);
1881 g_closure_unref (cc->closure);
1883 g_bsearch_array_free (node.class_closure_bsa, &g_class_closure_bconfig);
1885 g_free (node.accumulator);
1886 if (node.emission_hooks)
1888 g_hook_list_clear (node.emission_hooks);
1889 g_free (node.emission_hooks);
1895 * g_signal_override_class_closure:
1896 * @signal_id: the signal id
1897 * @instance_type: the instance type on which to override the class closure
1899 * @class_closure: the closure.
1901 * Overrides the class closure (i.e. the default handler) for the given signal
1902 * for emissions on instances of @instance_type. @instance_type must be derived
1903 * from the type to which the signal belongs.
1905 * See g_signal_chain_from_overridden() and
1906 * g_signal_chain_from_overridden_handler() for how to chain up to the
1907 * parent class closure from inside the overridden one.
1910 g_signal_override_class_closure (guint signal_id,
1911 GType instance_type,
1912 GClosure *class_closure)
1916 g_return_if_fail (signal_id > 0);
1917 g_return_if_fail (class_closure != NULL);
1920 node = LOOKUP_SIGNAL_NODE (signal_id);
1921 node_check_deprecated (node);
1922 if (!g_type_is_a (instance_type, node->itype))
1923 g_warning ("%s: type '%s' cannot be overridden for signal id '%u'", G_STRLOC, type_debug_name (instance_type), signal_id);
1926 ClassClosure *cc = signal_find_class_closure (node, instance_type);
1928 if (cc && cc->instance_type == instance_type)
1929 g_warning ("%s: type '%s' is already overridden for signal id '%u'", G_STRLOC, type_debug_name (instance_type), signal_id);
1931 signal_add_class_closure (node, instance_type, class_closure);
1937 * g_signal_override_class_handler:
1938 * @signal_name: the name for the signal
1939 * @instance_type: the instance type on which to override the class handler
1941 * @class_handler: the handler.
1943 * Overrides the class closure (i.e. the default handler) for the
1944 * given signal for emissions on instances of @instance_type with
1945 * callback @class_handler. @instance_type must be derived from the
1946 * type to which the signal belongs.
1948 * See g_signal_chain_from_overridden() and
1949 * g_signal_chain_from_overridden_handler() for how to chain up to the
1950 * parent class closure from inside the overridden one.
1955 g_signal_override_class_handler (const gchar *signal_name,
1956 GType instance_type,
1957 GCallback class_handler)
1961 g_return_if_fail (signal_name != NULL);
1962 g_return_if_fail (instance_type != G_TYPE_NONE);
1963 g_return_if_fail (class_handler != NULL);
1965 signal_id = g_signal_lookup (signal_name, instance_type);
1968 g_signal_override_class_closure (signal_id, instance_type,
1969 g_cclosure_new (class_handler, NULL, NULL));
1971 g_warning ("%s: signal name '%s' is invalid for type id '%"G_GSIZE_FORMAT"'",
1972 G_STRLOC, signal_name, instance_type);
1977 * g_signal_chain_from_overridden:
1978 * @instance_and_params: (array) the argument list of the signal emission.
1979 * The first element in the array is a #GValue for the instance the signal
1980 * is being emitted on. The rest are any arguments to be passed to the signal.
1981 * @return_value: Location for the return value.
1983 * Calls the original class closure of a signal. This function should only
1984 * be called from an overridden class closure; see
1985 * g_signal_override_class_closure() and
1986 * g_signal_override_class_handler().
1989 g_signal_chain_from_overridden (const GValue *instance_and_params,
1990 GValue *return_value)
1992 GType chain_type = 0, restore_type = 0;
1993 Emission *emission = NULL;
1994 GClosure *closure = NULL;
1998 g_return_if_fail (instance_and_params != NULL);
1999 instance = g_value_peek_pointer (instance_and_params);
2000 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
2003 emission = emission_find_innermost (instance);
2006 SignalNode *node = LOOKUP_SIGNAL_NODE (emission->ihint.signal_id);
2008 g_assert (node != NULL); /* paranoid */
2010 /* we should probably do the same parameter checks as g_signal_emit() here.
2012 if (emission->chain_type != G_TYPE_NONE)
2014 ClassClosure *cc = signal_find_class_closure (node, emission->chain_type);
2016 g_assert (cc != NULL); /* closure currently in call stack */
2018 n_params = node->n_params;
2019 restore_type = cc->instance_type;
2020 cc = signal_find_class_closure (node, g_type_parent (cc->instance_type));
2021 if (cc && cc->instance_type != restore_type)
2023 closure = cc->closure;
2024 chain_type = cc->instance_type;
2028 g_warning ("%s: signal id '%u' cannot be chained from current emission stage for instance '%p'", G_STRLOC, node->signal_id, instance);
2031 g_warning ("%s: no signal is currently being emitted for instance '%p'", G_STRLOC, instance);
2035 emission->chain_type = chain_type;
2037 g_closure_invoke (closure,
2040 instance_and_params,
2043 emission->chain_type = restore_type;
2049 * g_signal_chain_from_overridden_handler: (skip)
2050 * @instance: the instance the signal is being emitted on.
2051 * @...: parameters to be passed to the parent class closure, followed by a
2052 * location for the return value. If the return type of the signal
2053 * is #G_TYPE_NONE, the return value location can be omitted.
2055 * Calls the original class closure of a signal. This function should
2056 * only be called from an overridden class closure; see
2057 * g_signal_override_class_closure() and
2058 * g_signal_override_class_handler().
2063 g_signal_chain_from_overridden_handler (gpointer instance,
2066 GType chain_type = 0, restore_type = 0;
2067 Emission *emission = NULL;
2068 GClosure *closure = NULL;
2072 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
2075 emission = emission_find_innermost (instance);
2078 node = LOOKUP_SIGNAL_NODE (emission->ihint.signal_id);
2080 g_assert (node != NULL); /* paranoid */
2082 /* we should probably do the same parameter checks as g_signal_emit() here.
2084 if (emission->chain_type != G_TYPE_NONE)
2086 ClassClosure *cc = signal_find_class_closure (node, emission->chain_type);
2088 g_assert (cc != NULL); /* closure currently in call stack */
2090 n_params = node->n_params;
2091 restore_type = cc->instance_type;
2092 cc = signal_find_class_closure (node, g_type_parent (cc->instance_type));
2093 if (cc && cc->instance_type != restore_type)
2095 closure = cc->closure;
2096 chain_type = cc->instance_type;
2100 g_warning ("%s: signal id '%u' cannot be chained from current emission stage for instance '%p'", G_STRLOC, node->signal_id, instance);
2103 g_warning ("%s: no signal is currently being emitted for instance '%p'", G_STRLOC, instance);
2107 GValue *instance_and_params;
2108 GType signal_return_type;
2109 GValue *param_values;
2113 va_start (var_args, instance);
2115 signal_return_type = node->return_type;
2116 instance_and_params = g_alloca (sizeof (GValue) * (n_params + 1));
2117 memset (instance_and_params, 0, sizeof (GValue) * (n_params + 1));
2118 param_values = instance_and_params + 1;
2120 for (i = 0; i < node->n_params; i++)
2123 GType ptype = node->param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE;
2124 gboolean static_scope = node->param_types[i] & G_SIGNAL_TYPE_STATIC_SCOPE;
2127 G_VALUE_COLLECT_INIT (param_values + i, ptype,
2129 static_scope ? G_VALUE_NOCOPY_CONTENTS : 0,
2133 g_warning ("%s: %s", G_STRLOC, error);
2136 /* we purposely leak the value here, it might not be
2137 * in a sane state if an error condition occoured
2140 g_value_unset (param_values + i);
2149 instance_and_params->g_type = 0;
2150 g_value_init_from_instance (instance_and_params, instance);
2153 emission->chain_type = chain_type;
2156 if (signal_return_type == G_TYPE_NONE)
2158 g_closure_invoke (closure,
2161 instance_and_params,
2166 GValue return_value = G_VALUE_INIT;
2167 gchar *error = NULL;
2168 GType rtype = signal_return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE;
2169 gboolean static_scope = signal_return_type & G_SIGNAL_TYPE_STATIC_SCOPE;
2171 g_value_init (&return_value, rtype);
2173 g_closure_invoke (closure,
2176 instance_and_params,
2179 G_VALUE_LCOPY (&return_value,
2181 static_scope ? G_VALUE_NOCOPY_CONTENTS : 0,
2185 g_value_unset (&return_value);
2189 g_warning ("%s: %s", G_STRLOC, error);
2192 /* we purposely leak the value here, it might not be
2193 * in a sane state if an error condition occurred
2198 for (i = 0; i < n_params; i++)
2199 g_value_unset (param_values + i);
2200 g_value_unset (instance_and_params);
2205 emission->chain_type = restore_type;
2211 * g_signal_get_invocation_hint:
2212 * @instance: (type GObject.Object): the instance to query
2214 * Returns the invocation hint of the innermost signal emission of instance.
2216 * Returns: (transfer none): the invocation hint of the innermost signal emission.
2218 GSignalInvocationHint*
2219 g_signal_get_invocation_hint (gpointer instance)
2221 Emission *emission = NULL;
2223 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), NULL);
2226 emission = emission_find_innermost (instance);
2229 return emission ? &emission->ihint : NULL;
2233 * g_signal_connect_closure_by_id:
2234 * @instance: (type GObject.Object): the instance to connect to.
2235 * @signal_id: the id of the signal.
2236 * @detail: the detail.
2237 * @closure: the closure to connect.
2238 * @after: whether the handler should be called before or after the
2239 * default handler of the signal.
2241 * Connects a closure to a signal for a particular object.
2243 * Returns: the handler id (always greater than 0 for successful connections)
2246 g_signal_connect_closure_by_id (gpointer instance,
2253 gulong handler_seq_no = 0;
2255 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
2256 g_return_val_if_fail (signal_id > 0, 0);
2257 g_return_val_if_fail (closure != NULL, 0);
2260 node = LOOKUP_SIGNAL_NODE (signal_id);
2263 if (detail && !(node->flags & G_SIGNAL_DETAILED))
2264 g_warning ("%s: signal id '%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
2265 else if (!g_type_is_a (G_TYPE_FROM_INSTANCE (instance), node->itype))
2266 g_warning ("%s: signal id '%u' is invalid for instance '%p'", G_STRLOC, signal_id, instance);
2269 Handler *handler = handler_new (after);
2271 handler_seq_no = handler->sequential_number;
2272 handler->detail = detail;
2273 handler->closure = g_closure_ref (closure);
2274 g_closure_sink (closure);
2275 add_invalid_closure_notify (handler, instance);
2276 handler_insert (signal_id, instance, handler);
2277 if (node->c_marshaller && G_CLOSURE_NEEDS_MARSHAL (closure))
2279 g_closure_set_marshal (closure, node->c_marshaller);
2280 if (node->va_marshaller)
2281 _g_closure_set_va_marshal (closure, node->va_marshaller);
2286 g_warning ("%s: signal id '%u' is invalid for instance '%p'", G_STRLOC, signal_id, instance);
2289 return handler_seq_no;
2293 * g_signal_connect_closure:
2294 * @instance: (type GObject.Object): the instance to connect to.
2295 * @detailed_signal: a string of the form "signal-name::detail".
2296 * @closure: the closure to connect.
2297 * @after: whether the handler should be called before or after the
2298 * default handler of the signal.
2300 * Connects a closure to a signal for a particular object.
2302 * Returns: the handler id (always greater than 0 for successful connections)
2305 g_signal_connect_closure (gpointer instance,
2306 const gchar *detailed_signal,
2311 gulong handler_seq_no = 0;
2315 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
2316 g_return_val_if_fail (detailed_signal != NULL, 0);
2317 g_return_val_if_fail (closure != NULL, 0);
2320 itype = G_TYPE_FROM_INSTANCE (instance);
2321 signal_id = signal_parse_name (detailed_signal, itype, &detail, TRUE);
2324 SignalNode *node = LOOKUP_SIGNAL_NODE (signal_id);
2326 if (detail && !(node->flags & G_SIGNAL_DETAILED))
2327 g_warning ("%s: signal '%s' does not support details", G_STRLOC, detailed_signal);
2328 else if (!g_type_is_a (itype, node->itype))
2329 g_warning ("%s: signal '%s' is invalid for instance '%p' of type '%s'",
2330 G_STRLOC, detailed_signal, instance, g_type_name (itype));
2333 Handler *handler = handler_new (after);
2335 handler_seq_no = handler->sequential_number;
2336 handler->detail = detail;
2337 handler->closure = g_closure_ref (closure);
2338 g_closure_sink (closure);
2339 add_invalid_closure_notify (handler, instance);
2340 handler_insert (signal_id, instance, handler);
2341 if (node->c_marshaller && G_CLOSURE_NEEDS_MARSHAL (handler->closure))
2343 g_closure_set_marshal (handler->closure, node->c_marshaller);
2344 if (node->va_marshaller)
2345 _g_closure_set_va_marshal (handler->closure, node->va_marshaller);
2350 g_warning ("%s: signal '%s' is invalid for instance '%p' of type '%s'",
2351 G_STRLOC, detailed_signal, instance, g_type_name (itype));
2354 return handler_seq_no;
2358 node_check_deprecated (const SignalNode *node)
2360 static const gchar * g_enable_diagnostic = NULL;
2362 if (G_UNLIKELY (!g_enable_diagnostic))
2364 g_enable_diagnostic = g_getenv ("G_ENABLE_DIAGNOSTIC");
2365 if (!g_enable_diagnostic)
2366 g_enable_diagnostic = "0";
2369 if (g_enable_diagnostic[0] == '1')
2371 if (node->flags & G_SIGNAL_DEPRECATED)
2373 g_warning ("The signal %s::%s is deprecated and shouldn't be used "
2374 "anymore. It will be removed in a future version.",
2375 type_debug_name (node->itype), node->name);
2381 * g_signal_connect_data:
2382 * @instance: (type GObject.Object): the instance to connect to.
2383 * @detailed_signal: a string of the form "signal-name::detail".
2384 * @c_handler: the #GCallback to connect.
2385 * @data: data to pass to @c_handler calls.
2386 * @destroy_data: a #GClosureNotify for @data.
2387 * @connect_flags: a combination of #GConnectFlags.
2389 * Connects a #GCallback function to a signal for a particular object. Similar
2390 * to g_signal_connect(), but allows to provide a #GClosureNotify for the data
2391 * which will be called when the signal handler is disconnected and no longer
2392 * used. Specify @connect_flags if you need `..._after()` or
2393 * `..._swapped()` variants of this function.
2395 * Returns: the handler id (always greater than 0 for successful connections)
2398 g_signal_connect_data (gpointer instance,
2399 const gchar *detailed_signal,
2400 GCallback c_handler,
2402 GClosureNotify destroy_data,
2403 GConnectFlags connect_flags)
2406 gulong handler_seq_no = 0;
2409 gboolean swapped, after;
2411 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
2412 g_return_val_if_fail (detailed_signal != NULL, 0);
2413 g_return_val_if_fail (c_handler != NULL, 0);
2415 swapped = (connect_flags & G_CONNECT_SWAPPED) != FALSE;
2416 after = (connect_flags & G_CONNECT_AFTER) != FALSE;
2419 itype = G_TYPE_FROM_INSTANCE (instance);
2420 signal_id = signal_parse_name (detailed_signal, itype, &detail, TRUE);
2423 SignalNode *node = LOOKUP_SIGNAL_NODE (signal_id);
2425 node_check_deprecated (node);
2427 if (detail && !(node->flags & G_SIGNAL_DETAILED))
2428 g_warning ("%s: signal '%s' does not support details", G_STRLOC, detailed_signal);
2429 else if (!g_type_is_a (itype, node->itype))
2430 g_warning ("%s: signal '%s' is invalid for instance '%p' of type '%s'",
2431 G_STRLOC, detailed_signal, instance, g_type_name (itype));
2434 Handler *handler = handler_new (after);
2436 handler_seq_no = handler->sequential_number;
2437 handler->detail = detail;
2438 handler->closure = g_closure_ref ((swapped ? g_cclosure_new_swap : g_cclosure_new) (c_handler, data, destroy_data));
2439 g_closure_sink (handler->closure);
2440 handler_insert (signal_id, instance, handler);
2441 if (node->c_marshaller && G_CLOSURE_NEEDS_MARSHAL (handler->closure))
2443 g_closure_set_marshal (handler->closure, node->c_marshaller);
2444 if (node->va_marshaller)
2445 _g_closure_set_va_marshal (handler->closure, node->va_marshaller);
2450 g_warning ("%s: signal '%s' is invalid for instance '%p' of type '%s'",
2451 G_STRLOC, detailed_signal, instance, g_type_name (itype));
2454 return handler_seq_no;
2458 * g_signal_handler_block:
2459 * @instance: (type GObject.Object): The instance to block the signal handler of.
2460 * @handler_id: Handler id of the handler to be blocked.
2462 * Blocks a handler of an instance so it will not be called during any
2463 * signal emissions unless it is unblocked again. Thus "blocking" a
2464 * signal handler means to temporarily deactive it, a signal handler
2465 * has to be unblocked exactly the same amount of times it has been
2466 * blocked before to become active again.
2468 * The @handler_id has to be a valid signal handler id, connected to a
2469 * signal of @instance.
2472 g_signal_handler_block (gpointer instance,
2477 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
2478 g_return_if_fail (handler_id > 0);
2481 handler = handler_lookup (instance, handler_id, NULL, NULL);
2484 #ifndef G_DISABLE_CHECKS
2485 if (handler->block_count >= HANDLER_MAX_BLOCK_COUNT - 1)
2486 g_error (G_STRLOC ": handler block_count overflow, %s", REPORT_BUG);
2488 handler->block_count += 1;
2491 g_warning ("%s: instance '%p' has no handler with id '%lu'", G_STRLOC, instance, handler_id);
2496 * g_signal_handler_unblock:
2497 * @instance: (type GObject.Object): The instance to unblock the signal handler of.
2498 * @handler_id: Handler id of the handler to be unblocked.
2500 * Undoes the effect of a previous g_signal_handler_block() call. A
2501 * blocked handler is skipped during signal emissions and will not be
2502 * invoked, unblocking it (for exactly the amount of times it has been
2503 * blocked before) reverts its "blocked" state, so the handler will be
2504 * recognized by the signal system and is called upon future or
2505 * currently ongoing signal emissions (since the order in which
2506 * handlers are called during signal emissions is deterministic,
2507 * whether the unblocked handler in question is called as part of a
2508 * currently ongoing emission depends on how far that emission has
2511 * The @handler_id has to be a valid id of a signal handler that is
2512 * connected to a signal of @instance and is currently blocked.
2515 g_signal_handler_unblock (gpointer instance,
2520 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
2521 g_return_if_fail (handler_id > 0);
2524 handler = handler_lookup (instance, handler_id, NULL, NULL);
2527 if (handler->block_count)
2528 handler->block_count -= 1;
2530 g_warning (G_STRLOC ": handler '%lu' of instance '%p' is not blocked", handler_id, instance);
2533 g_warning ("%s: instance '%p' has no handler with id '%lu'", G_STRLOC, instance, handler_id);
2538 * g_signal_handler_disconnect:
2539 * @instance: (type GObject.Object): The instance to remove the signal handler from.
2540 * @handler_id: Handler id of the handler to be disconnected.
2542 * Disconnects a handler from an instance so it will not be called during
2543 * any future or currently ongoing emissions of the signal it has been
2544 * connected to. The @handler_id becomes invalid and may be reused.
2546 * The @handler_id has to be a valid signal handler id, connected to a
2547 * signal of @instance.
2550 g_signal_handler_disconnect (gpointer instance,
2556 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
2557 g_return_if_fail (handler_id > 0);
2560 handler = handler_lookup (instance, handler_id, NULL, &signal_id);
2563 handler->sequential_number = 0;
2564 handler->block_count = 1;
2565 remove_invalid_closure_notify (handler, instance);
2566 handler_unref_R (signal_id, instance, handler);
2569 g_warning ("%s: instance '%p' has no handler with id '%lu'", G_STRLOC, instance, handler_id);
2574 * g_signal_handler_is_connected:
2575 * @instance: (type GObject.Object): The instance where a signal handler is sought.
2576 * @handler_id: the handler id.
2578 * Returns whether @handler_id is the id of a handler connected to @instance.
2580 * Returns: whether @handler_id identifies a handler connected to @instance.
2583 g_signal_handler_is_connected (gpointer instance,
2589 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), FALSE);
2592 handler = handler_lookup (instance, handler_id, NULL, NULL);
2593 connected = handler != NULL;
2600 * g_signal_handlers_destroy:
2601 * @instance: (type GObject.Object): The instance whose signal handlers are destroyed
2603 * Destroy all signal handlers of a type instance. This function is
2604 * an implementation detail of the #GObject dispose implementation,
2605 * and should not be used outside of the type system.
2608 g_signal_handlers_destroy (gpointer instance)
2610 GBSearchArray *hlbsa;
2612 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
2615 hlbsa = g_hash_table_lookup (g_handler_list_bsa_ht, instance);
2620 /* reentrancy caution, delete instance trace first */
2621 g_hash_table_remove (g_handler_list_bsa_ht, instance);
2623 for (i = 0; i < hlbsa->n_nodes; i++)
2625 HandlerList *hlist = g_bsearch_array_get_nth (hlbsa, &g_signal_hlbsa_bconfig, i);
2626 Handler *handler = hlist->handlers;
2630 Handler *tmp = handler;
2632 handler = tmp->next;
2633 tmp->block_count = 1;
2634 /* cruel unlink, this works because _all_ handlers vanish */
2637 if (tmp->sequential_number)
2639 remove_invalid_closure_notify (tmp, instance);
2640 tmp->sequential_number = 0;
2641 handler_unref_R (0, NULL, tmp);
2645 g_bsearch_array_free (hlbsa, &g_signal_hlbsa_bconfig);
2651 * g_signal_handler_find:
2652 * @instance: (type GObject.Object): The instance owning the signal handler to be found.
2653 * @mask: Mask indicating which of @signal_id, @detail, @closure, @func
2654 * and/or @data the handler has to match.
2655 * @signal_id: Signal the handler has to be connected to.
2656 * @detail: Signal detail the handler has to be connected to.
2657 * @closure: (allow-none): The closure the handler will invoke.
2658 * @func: The C closure callback of the handler (useless for non-C closures).
2659 * @data: The closure data of the handler's closure.
2661 * Finds the first signal handler that matches certain selection criteria.
2662 * The criteria mask is passed as an OR-ed combination of #GSignalMatchType
2663 * flags, and the criteria values are passed as arguments.
2664 * The match @mask has to be non-0 for successful matches.
2665 * If no handler was found, 0 is returned.
2667 * Returns: A valid non-0 signal handler id for a successful match.
2670 g_signal_handler_find (gpointer instance,
2671 GSignalMatchType mask,
2678 gulong handler_seq_no = 0;
2680 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
2681 g_return_val_if_fail ((mask & ~G_SIGNAL_MATCH_MASK) == 0, 0);
2683 if (mask & G_SIGNAL_MATCH_MASK)
2685 HandlerMatch *mlist;
2688 mlist = handlers_find (instance, mask, signal_id, detail, closure, func, data, TRUE);
2691 handler_seq_no = mlist->handler->sequential_number;
2692 handler_match_free1_R (mlist, instance);
2697 return handler_seq_no;
2701 signal_handlers_foreach_matched_R (gpointer instance,
2702 GSignalMatchType mask,
2708 void (*callback) (gpointer instance,
2709 gulong handler_seq_no))
2711 HandlerMatch *mlist;
2712 guint n_handlers = 0;
2714 mlist = handlers_find (instance, mask, signal_id, detail, closure, func, data, FALSE);
2718 if (mlist->handler->sequential_number)
2721 callback (instance, mlist->handler->sequential_number);
2724 mlist = handler_match_free1_R (mlist, instance);
2731 * g_signal_handlers_block_matched:
2732 * @instance: (type GObject.Object): The instance to block handlers from.
2733 * @mask: Mask indicating which of @signal_id, @detail, @closure, @func
2734 * and/or @data the handlers have to match.
2735 * @signal_id: Signal the handlers have to be connected to.
2736 * @detail: Signal detail the handlers have to be connected to.
2737 * @closure: (allow-none): The closure the handlers will invoke.
2738 * @func: The C closure callback of the handlers (useless for non-C closures).
2739 * @data: The closure data of the handlers' closures.
2741 * Blocks all handlers on an instance that match a certain selection criteria.
2742 * The criteria mask is passed as an OR-ed combination of #GSignalMatchType
2743 * flags, and the criteria values are passed as arguments.
2744 * Passing at least one of the %G_SIGNAL_MATCH_CLOSURE, %G_SIGNAL_MATCH_FUNC
2745 * or %G_SIGNAL_MATCH_DATA match flags is required for successful matches.
2746 * If no handlers were found, 0 is returned, the number of blocked handlers
2749 * Returns: The number of handlers that matched.
2752 g_signal_handlers_block_matched (gpointer instance,
2753 GSignalMatchType mask,
2760 guint n_handlers = 0;
2762 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
2763 g_return_val_if_fail ((mask & ~G_SIGNAL_MATCH_MASK) == 0, 0);
2765 if (mask & (G_SIGNAL_MATCH_CLOSURE | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA))
2768 n_handlers = signal_handlers_foreach_matched_R (instance, mask, signal_id, detail,
2769 closure, func, data,
2770 g_signal_handler_block);
2778 * g_signal_handlers_unblock_matched:
2779 * @instance: (type GObject.Object): The instance to unblock handlers from.
2780 * @mask: Mask indicating which of @signal_id, @detail, @closure, @func
2781 * and/or @data the handlers have to match.
2782 * @signal_id: Signal the handlers have to be connected to.
2783 * @detail: Signal detail the handlers have to be connected to.
2784 * @closure: (allow-none): The closure the handlers will invoke.
2785 * @func: The C closure callback of the handlers (useless for non-C closures).
2786 * @data: The closure data of the handlers' closures.
2788 * Unblocks all handlers on an instance that match a certain selection
2789 * criteria. The criteria mask is passed as an OR-ed combination of
2790 * #GSignalMatchType flags, and the criteria values are passed as arguments.
2791 * Passing at least one of the %G_SIGNAL_MATCH_CLOSURE, %G_SIGNAL_MATCH_FUNC
2792 * or %G_SIGNAL_MATCH_DATA match flags is required for successful matches.
2793 * If no handlers were found, 0 is returned, the number of unblocked handlers
2794 * otherwise. The match criteria should not apply to any handlers that are
2795 * not currently blocked.
2797 * Returns: The number of handlers that matched.
2800 g_signal_handlers_unblock_matched (gpointer instance,
2801 GSignalMatchType mask,
2808 guint n_handlers = 0;
2810 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
2811 g_return_val_if_fail ((mask & ~G_SIGNAL_MATCH_MASK) == 0, 0);
2813 if (mask & (G_SIGNAL_MATCH_CLOSURE | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA))
2816 n_handlers = signal_handlers_foreach_matched_R (instance, mask, signal_id, detail,
2817 closure, func, data,
2818 g_signal_handler_unblock);
2826 * g_signal_handlers_disconnect_matched:
2827 * @instance: (type GObject.Object): The instance to remove handlers from.
2828 * @mask: Mask indicating which of @signal_id, @detail, @closure, @func
2829 * and/or @data the handlers have to match.
2830 * @signal_id: Signal the handlers have to be connected to.
2831 * @detail: Signal detail the handlers have to be connected to.
2832 * @closure: (allow-none): The closure the handlers will invoke.
2833 * @func: The C closure callback of the handlers (useless for non-C closures).
2834 * @data: The closure data of the handlers' closures.
2836 * Disconnects all handlers on an instance that match a certain
2837 * selection criteria. The criteria mask is passed as an OR-ed
2838 * combination of #GSignalMatchType flags, and the criteria values are
2839 * passed as arguments. Passing at least one of the
2840 * %G_SIGNAL_MATCH_CLOSURE, %G_SIGNAL_MATCH_FUNC or
2841 * %G_SIGNAL_MATCH_DATA match flags is required for successful
2842 * matches. If no handlers were found, 0 is returned, the number of
2843 * disconnected handlers otherwise.
2845 * Returns: The number of handlers that matched.
2848 g_signal_handlers_disconnect_matched (gpointer instance,
2849 GSignalMatchType mask,
2856 guint n_handlers = 0;
2858 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
2859 g_return_val_if_fail ((mask & ~G_SIGNAL_MATCH_MASK) == 0, 0);
2861 if (mask & (G_SIGNAL_MATCH_CLOSURE | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA))
2864 n_handlers = signal_handlers_foreach_matched_R (instance, mask, signal_id, detail,
2865 closure, func, data,
2866 g_signal_handler_disconnect);
2874 * g_signal_has_handler_pending:
2875 * @instance: (type GObject.Object): the object whose signal handlers are sought.
2876 * @signal_id: the signal id.
2877 * @detail: the detail.
2878 * @may_be_blocked: whether blocked handlers should count as match.
2880 * Returns whether there are any handlers connected to @instance for the
2881 * given signal id and detail.
2883 * If @detail is 0 then it will only match handlers that were connected
2884 * without detail. If @detail is non-zero then it will match handlers
2885 * connected both without detail and with the given detail. This is
2886 * consistent with how a signal emitted with @detail would be delivered
2887 * to those handlers.
2889 * One example of when you might use this is when the arguments to the
2890 * signal are difficult to compute. A class implementor may opt to not
2891 * emit the signal if no one is attached anyway, thus saving the cost
2892 * of building the arguments.
2894 * Returns: %TRUE if a handler is connected to the signal, %FALSE
2898 g_signal_has_handler_pending (gpointer instance,
2901 gboolean may_be_blocked)
2903 HandlerMatch *mlist;
2904 gboolean has_pending;
2906 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), FALSE);
2907 g_return_val_if_fail (signal_id > 0, FALSE);
2912 SignalNode *node = LOOKUP_SIGNAL_NODE (signal_id);
2914 if (!(node->flags & G_SIGNAL_DETAILED))
2916 g_warning ("%s: signal id '%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
2921 mlist = handlers_find (instance,
2922 (G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | (may_be_blocked ? 0 : G_SIGNAL_MATCH_UNBLOCKED)),
2923 signal_id, detail, NULL, NULL, NULL, TRUE);
2927 handler_match_free1_R (mlist, instance);
2930 has_pending = FALSE;
2938 * @instance_and_params: (array): argument list for the signal emission.
2939 * The first element in the array is a #GValue for the instance the signal
2940 * is being emitted on. The rest are any arguments to be passed to the signal.
2941 * @signal_id: the signal id
2942 * @detail: the detail
2943 * @return_value: Location to store the return value of the signal emission.
2947 * Note that g_signal_emitv() doesn't change @return_value if no handlers are
2948 * connected, in contrast to g_signal_emit() and g_signal_emit_valist().
2951 g_signal_emitv (const GValue *instance_and_params,
2954 GValue *return_value)
2958 #ifdef G_ENABLE_DEBUG
2959 const GValue *param_values;
2963 g_return_if_fail (instance_and_params != NULL);
2964 instance = g_value_peek_pointer (instance_and_params);
2965 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
2966 g_return_if_fail (signal_id > 0);
2968 #ifdef G_ENABLE_DEBUG
2969 param_values = instance_and_params + 1;
2973 node = LOOKUP_SIGNAL_NODE (signal_id);
2974 if (!node || !g_type_is_a (G_TYPE_FROM_INSTANCE (instance), node->itype))
2976 g_warning ("%s: signal id '%u' is invalid for instance '%p'", G_STRLOC, signal_id, instance);
2980 #ifdef G_ENABLE_DEBUG
2981 if (detail && !(node->flags & G_SIGNAL_DETAILED))
2983 g_warning ("%s: signal id '%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
2987 for (i = 0; i < node->n_params; i++)
2988 if (!G_TYPE_CHECK_VALUE_TYPE (param_values + i, node->param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE))
2990 g_critical ("%s: value for '%s' parameter %u for signal \"%s\" is of type '%s'",
2992 type_debug_name (node->param_types[i]),
2995 G_VALUE_TYPE_NAME (param_values + i));
2999 if (node->return_type != G_TYPE_NONE)
3003 g_critical ("%s: return value '%s' for signal \"%s\" is (NULL)",
3005 type_debug_name (node->return_type),
3010 else if (!node->accumulator && !G_TYPE_CHECK_VALUE_TYPE (return_value, node->return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE))
3012 g_critical ("%s: return value '%s' for signal \"%s\" is of type '%s'",
3014 type_debug_name (node->return_type),
3016 G_VALUE_TYPE_NAME (return_value));
3022 return_value = NULL;
3023 #endif /* G_ENABLE_DEBUG */
3025 /* optimize NOP emissions */
3026 if (!node->single_va_closure_is_valid)
3027 node_update_single_va_closure (node);
3029 if (node->single_va_closure != NULL &&
3030 (node->single_va_closure == SINGLE_VA_CLOSURE_EMPTY_MAGIC ||
3031 _g_closure_is_void (node->single_va_closure, instance)))
3033 HandlerList* hlist = handler_list_lookup (node->signal_id, instance);
3034 if (hlist == NULL || hlist->handlers == NULL)
3036 /* nothing to do to emit this signal */
3038 /* g_printerr ("omitting emission of \"%s\"\n", node->name); */
3044 signal_emit_unlocked_R (node, detail, instance, return_value, instance_and_params);
3047 static inline gboolean
3048 accumulate (GSignalInvocationHint *ihint,
3049 GValue *return_accu,
3050 GValue *handler_return,
3051 SignalAccumulator *accumulator)
3053 gboolean continue_emission;
3058 continue_emission = accumulator->func (ihint, return_accu, handler_return, accumulator->data);
3059 g_value_reset (handler_return);
3061 return continue_emission;
3065 * g_signal_emit_valist: (skip)
3066 * @instance: the instance the signal is being emitted on.
3067 * @signal_id: the signal id
3068 * @detail: the detail
3069 * @var_args: a list of parameters to be passed to the signal, followed by a
3070 * location for the return value. If the return type of the signal
3071 * is #G_TYPE_NONE, the return value location can be omitted.
3075 * Note that g_signal_emit_valist() resets the return value to the default
3076 * if no handlers are connected, in contrast to g_signal_emitv().
3079 g_signal_emit_valist (gpointer instance,
3084 GValue *instance_and_params;
3085 GType signal_return_type;
3086 GValue *param_values;
3090 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
3091 g_return_if_fail (signal_id > 0);
3094 node = LOOKUP_SIGNAL_NODE (signal_id);
3095 if (!node || !g_type_is_a (G_TYPE_FROM_INSTANCE (instance), node->itype))
3097 g_warning ("%s: signal id '%u' is invalid for instance '%p'", G_STRLOC, signal_id, instance);
3101 #ifndef G_DISABLE_CHECKS
3102 if (detail && !(node->flags & G_SIGNAL_DETAILED))
3104 g_warning ("%s: signal id '%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
3108 #endif /* !G_DISABLE_CHECKS */
3110 if (!node->single_va_closure_is_valid)
3111 node_update_single_va_closure (node);
3113 if (node->single_va_closure != NULL)
3115 HandlerList* hlist = handler_list_lookup (node->signal_id, instance);
3116 Handler *fastpath_handler = NULL;
3118 GClosure *closure = NULL;
3119 gboolean fastpath = TRUE;
3120 GSignalFlags run_type = G_SIGNAL_RUN_FIRST;
3122 if (node->single_va_closure != SINGLE_VA_CLOSURE_EMPTY_MAGIC &&
3123 !_g_closure_is_void (node->single_va_closure, instance))
3125 if (_g_closure_supports_invoke_va (node->single_va_closure))
3127 closure = node->single_va_closure;
3128 if (node->single_va_closure_is_after)
3129 run_type = G_SIGNAL_RUN_LAST;
3131 run_type = G_SIGNAL_RUN_FIRST;
3137 for (l = hlist ? hlist->handlers : NULL; fastpath && l != NULL; l = l->next)
3139 if (!l->block_count &&
3140 (!l->detail || l->detail == detail))
3142 if (closure != NULL || !_g_closure_supports_invoke_va (l->closure))
3149 fastpath_handler = l;
3150 closure = l->closure;
3152 run_type = G_SIGNAL_RUN_LAST;
3154 run_type = G_SIGNAL_RUN_FIRST;
3159 if (fastpath && closure == NULL && node->return_type == G_TYPE_NONE)
3165 /* Don't allow no-recurse emission as we might have to restart, which means
3166 we will run multiple handlers and thus must ref all arguments */
3167 if (closure != NULL && (node->flags & (G_SIGNAL_NO_RECURSE)) != 0)
3172 SignalAccumulator *accumulator;
3174 GValue *return_accu, accu = G_VALUE_INIT;
3176 GType instance_type = G_TYPE_FROM_INSTANCE (instance);
3177 GValue emission_return = G_VALUE_INIT;
3178 GType rtype = node->return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE;
3179 gboolean static_scope = node->return_type & G_SIGNAL_TYPE_STATIC_SCOPE;
3181 signal_id = node->signal_id;
3182 accumulator = node->accumulator;
3183 if (rtype == G_TYPE_NONE)
3185 else if (accumulator)
3186 return_accu = &accu;
3188 return_accu = &emission_return;
3190 emission.instance = instance;
3191 emission.ihint.signal_id = signal_id;
3192 emission.ihint.detail = detail;
3193 emission.ihint.run_type = run_type;
3194 emission.state = EMISSION_RUN;
3195 emission.chain_type = instance_type;
3196 emission_push (&emission);
3198 if (fastpath_handler)
3199 handler_ref (fastpath_handler);
3203 TRACE(GOBJECT_SIGNAL_EMIT(signal_id, detail, instance, instance_type));
3205 if (rtype != G_TYPE_NONE)
3206 g_value_init (&emission_return, rtype);
3209 g_value_init (&accu, rtype);
3211 if (closure != NULL)
3213 g_object_ref (instance);
3214 _g_closure_invoke_va (closure,
3220 accumulate (&emission.ihint, &emission_return, &accu, accumulator);
3225 emission.chain_type = G_TYPE_NONE;
3226 emission_pop (&emission);
3228 if (fastpath_handler)
3229 handler_unref_R (signal_id, instance, fastpath_handler);
3234 g_value_unset (&accu);
3236 if (rtype != G_TYPE_NONE)
3238 gchar *error = NULL;
3239 for (i = 0; i < node->n_params; i++)
3241 GType ptype = node->param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE;
3242 G_VALUE_COLLECT_SKIP (ptype, var_args);
3245 G_VALUE_LCOPY (&emission_return,
3247 static_scope ? G_VALUE_NOCOPY_CONTENTS : 0,
3250 g_value_unset (&emission_return);
3253 g_warning ("%s: %s", G_STRLOC, error);
3255 /* we purposely leak the value here, it might not be
3256 * in a sane state if an error condition occurred
3261 TRACE(GOBJECT_SIGNAL_EMIT_END(signal_id, detail, instance, instance_type));
3263 if (closure != NULL)
3264 g_object_unref (instance);
3271 n_params = node->n_params;
3272 signal_return_type = node->return_type;
3273 instance_and_params = g_alloca (sizeof (GValue) * (n_params + 1));
3274 memset (instance_and_params, 0, sizeof (GValue) * (n_params + 1));
3275 param_values = instance_and_params + 1;
3277 for (i = 0; i < node->n_params; i++)
3280 GType ptype = node->param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE;
3281 gboolean static_scope = node->param_types[i] & G_SIGNAL_TYPE_STATIC_SCOPE;
3283 G_VALUE_COLLECT_INIT (param_values + i, ptype,
3285 static_scope ? G_VALUE_NOCOPY_CONTENTS : 0,
3289 g_warning ("%s: %s", G_STRLOC, error);
3292 /* we purposely leak the value here, it might not be
3293 * in a sane state if an error condition occoured
3296 g_value_unset (param_values + i);
3302 instance_and_params->g_type = 0;
3303 g_value_init_from_instance (instance_and_params, instance);
3304 if (signal_return_type == G_TYPE_NONE)
3305 signal_emit_unlocked_R (node, detail, instance, NULL, instance_and_params);
3308 GValue return_value = G_VALUE_INIT;
3309 gchar *error = NULL;
3310 GType rtype = signal_return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE;
3311 gboolean static_scope = signal_return_type & G_SIGNAL_TYPE_STATIC_SCOPE;
3313 g_value_init (&return_value, rtype);
3315 signal_emit_unlocked_R (node, detail, instance, &return_value, instance_and_params);
3317 G_VALUE_LCOPY (&return_value,
3319 static_scope ? G_VALUE_NOCOPY_CONTENTS : 0,
3322 g_value_unset (&return_value);
3325 g_warning ("%s: %s", G_STRLOC, error);
3328 /* we purposely leak the value here, it might not be
3329 * in a sane state if an error condition occurred
3333 for (i = 0; i < n_params; i++)
3334 g_value_unset (param_values + i);
3335 g_value_unset (instance_and_params);
3340 * @instance: (type GObject.Object): the instance the signal is being emitted on.
3341 * @signal_id: the signal id
3342 * @detail: the detail
3343 * @...: parameters to be passed to the signal, followed by a
3344 * location for the return value. If the return type of the signal
3345 * is #G_TYPE_NONE, the return value location can be omitted.
3349 * Note that g_signal_emit() resets the return value to the default
3350 * if no handlers are connected, in contrast to g_signal_emitv().
3353 g_signal_emit (gpointer instance,
3360 va_start (var_args, detail);
3361 g_signal_emit_valist (instance, signal_id, detail, var_args);
3366 * g_signal_emit_by_name:
3367 * @instance: (type GObject.Object): the instance the signal is being emitted on.
3368 * @detailed_signal: a string of the form "signal-name::detail".
3369 * @...: parameters to be passed to the signal, followed by a
3370 * location for the return value. If the return type of the signal
3371 * is #G_TYPE_NONE, the return value location can be omitted.
3375 * Note that g_signal_emit_by_name() resets the return value to the default
3376 * if no handlers are connected, in contrast to g_signal_emitv().
3379 g_signal_emit_by_name (gpointer instance,
3380 const gchar *detailed_signal,
3387 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
3388 g_return_if_fail (detailed_signal != NULL);
3390 itype = G_TYPE_FROM_INSTANCE (instance);
3393 signal_id = signal_parse_name (detailed_signal, itype, &detail, TRUE);
3400 va_start (var_args, detailed_signal);
3401 g_signal_emit_valist (instance, signal_id, detail, var_args);
3405 g_warning ("%s: signal name '%s' is invalid for instance '%p' of type '%s'",
3406 G_STRLOC, detailed_signal, instance, g_type_name (itype));
3410 signal_emit_unlocked_R (SignalNode *node,
3413 GValue *emission_return,
3414 const GValue *instance_and_params)
3416 SignalAccumulator *accumulator;
3418 GClosure *class_closure;
3420 Handler *handler_list = NULL;
3421 GValue *return_accu, accu = G_VALUE_INIT;
3423 gulong max_sequential_handler_number;
3424 gboolean return_value_altered = FALSE;
3426 TRACE(GOBJECT_SIGNAL_EMIT(node->signal_id, detail, instance, G_TYPE_FROM_INSTANCE (instance)));
3429 signal_id = node->signal_id;
3431 if (node->flags & G_SIGNAL_NO_RECURSE)
3433 Emission *node = emission_find (signal_id, detail, instance);
3437 node->state = EMISSION_RESTART;
3439 return return_value_altered;
3442 accumulator = node->accumulator;
3446 g_value_init (&accu, node->return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE);
3447 return_accu = &accu;
3451 return_accu = emission_return;
3452 emission.instance = instance;
3453 emission.ihint.signal_id = node->signal_id;
3454 emission.ihint.detail = detail;
3455 emission.ihint.run_type = 0;
3457 emission.chain_type = G_TYPE_NONE;
3458 emission_push (&emission);
3459 class_closure = signal_lookup_closure (node, instance);
3464 handler_unref_R (signal_id, instance, handler_list);
3465 max_sequential_handler_number = g_handler_sequential_number;
3466 hlist = handler_list_lookup (signal_id, instance);
3467 handler_list = hlist ? hlist->handlers : NULL;
3469 handler_ref (handler_list);
3471 emission.ihint.run_type = G_SIGNAL_RUN_FIRST;
3473 if ((node->flags & G_SIGNAL_RUN_FIRST) && class_closure)
3475 emission.state = EMISSION_RUN;
3477 emission.chain_type = G_TYPE_FROM_INSTANCE (instance);
3479 g_closure_invoke (class_closure,
3482 instance_and_params,
3484 if (!accumulate (&emission.ihint, emission_return, &accu, accumulator) &&
3485 emission.state == EMISSION_RUN)
3486 emission.state = EMISSION_STOP;
3488 emission.chain_type = G_TYPE_NONE;
3489 return_value_altered = TRUE;
3491 if (emission.state == EMISSION_STOP)
3493 else if (emission.state == EMISSION_RESTART)
3497 if (node->emission_hooks)
3499 gboolean need_destroy, was_in_call, may_recurse = TRUE;
3502 emission.state = EMISSION_HOOK;
3503 hook = g_hook_first_valid (node->emission_hooks, may_recurse);
3506 SignalHook *signal_hook = SIGNAL_HOOK (hook);
3508 if (!signal_hook->detail || signal_hook->detail == detail)
3510 GSignalEmissionHook hook_func = (GSignalEmissionHook) hook->func;
3512 was_in_call = G_HOOK_IN_CALL (hook);
3513 hook->flags |= G_HOOK_FLAG_IN_CALL;
3515 need_destroy = !hook_func (&emission.ihint, node->n_params + 1, instance_and_params, hook->data);
3518 hook->flags &= ~G_HOOK_FLAG_IN_CALL;
3520 g_hook_destroy_link (node->emission_hooks, hook);
3522 hook = g_hook_next_valid (node->emission_hooks, hook, may_recurse);
3525 if (emission.state == EMISSION_RESTART)
3531 Handler *handler = handler_list;
3533 emission.state = EMISSION_RUN;
3534 handler_ref (handler);
3541 handler_unref_R (signal_id, instance, handler_list);
3542 handler_list = handler;
3545 else if (!handler->block_count && (!handler->detail || handler->detail == detail) &&
3546 handler->sequential_number < max_sequential_handler_number)
3549 g_closure_invoke (handler->closure,
3552 instance_and_params,
3554 if (!accumulate (&emission.ihint, emission_return, &accu, accumulator) &&
3555 emission.state == EMISSION_RUN)
3556 emission.state = EMISSION_STOP;
3558 return_value_altered = TRUE;
3560 tmp = emission.state == EMISSION_RUN ? handler->next : NULL;
3563 tmp = handler->next;
3567 handler_unref_R (signal_id, instance, handler_list);
3568 handler_list = handler;
3573 if (emission.state == EMISSION_STOP)
3575 else if (emission.state == EMISSION_RESTART)
3579 emission.ihint.run_type = G_SIGNAL_RUN_LAST;
3581 if ((node->flags & G_SIGNAL_RUN_LAST) && class_closure)
3583 emission.state = EMISSION_RUN;
3585 emission.chain_type = G_TYPE_FROM_INSTANCE (instance);
3587 g_closure_invoke (class_closure,
3590 instance_and_params,
3592 if (!accumulate (&emission.ihint, emission_return, &accu, accumulator) &&
3593 emission.state == EMISSION_RUN)
3594 emission.state = EMISSION_STOP;
3596 emission.chain_type = G_TYPE_NONE;
3597 return_value_altered = TRUE;
3599 if (emission.state == EMISSION_STOP)
3601 else if (emission.state == EMISSION_RESTART)
3607 Handler *handler = handler_list;
3609 emission.state = EMISSION_RUN;
3610 handler_ref (handler);
3615 if (handler->after && !handler->block_count && (!handler->detail || handler->detail == detail) &&
3616 handler->sequential_number < max_sequential_handler_number)
3619 g_closure_invoke (handler->closure,
3622 instance_and_params,
3624 if (!accumulate (&emission.ihint, emission_return, &accu, accumulator) &&
3625 emission.state == EMISSION_RUN)
3626 emission.state = EMISSION_STOP;
3628 return_value_altered = TRUE;
3630 tmp = emission.state == EMISSION_RUN ? handler->next : NULL;
3633 tmp = handler->next;
3637 handler_unref_R (signal_id, instance, handler);
3642 if (emission.state == EMISSION_STOP)
3644 else if (emission.state == EMISSION_RESTART)
3650 emission.ihint.run_type = G_SIGNAL_RUN_CLEANUP;
3652 if ((node->flags & G_SIGNAL_RUN_CLEANUP) && class_closure)
3654 gboolean need_unset = FALSE;
3656 emission.state = EMISSION_STOP;
3658 emission.chain_type = G_TYPE_FROM_INSTANCE (instance);
3660 if (node->return_type != G_TYPE_NONE && !accumulator)
3662 g_value_init (&accu, node->return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE);
3665 g_closure_invoke (class_closure,
3666 node->return_type != G_TYPE_NONE ? &accu : NULL,
3668 instance_and_params,
3671 g_value_unset (&accu);
3673 emission.chain_type = G_TYPE_NONE;
3675 if (emission.state == EMISSION_RESTART)
3680 handler_unref_R (signal_id, instance, handler_list);
3682 emission_pop (&emission);
3685 g_value_unset (&accu);
3687 TRACE(GOBJECT_SIGNAL_EMIT_END(node->signal_id, detail, instance, G_TYPE_FROM_INSTANCE (instance)));
3689 return return_value_altered;
3693 add_invalid_closure_notify (Handler *handler,
3696 g_closure_add_invalidate_notifier (handler->closure, instance, invalid_closure_notify);
3697 handler->has_invalid_closure_notify = 1;
3701 remove_invalid_closure_notify (Handler *handler,
3704 if (handler->has_invalid_closure_notify)
3706 g_closure_remove_invalidate_notifier (handler->closure, instance, invalid_closure_notify);
3707 handler->has_invalid_closure_notify = 0;
3712 invalid_closure_notify (gpointer instance,
3720 handler = handler_lookup (instance, 0, closure, &signal_id);
3721 g_assert (handler->closure == closure);
3723 handler->sequential_number = 0;
3724 handler->block_count = 1;
3725 handler_unref_R (signal_id, instance, handler);
3731 type_debug_name (GType type)
3735 const char *name = g_type_name (type & ~G_SIGNAL_TYPE_STATIC_SCOPE);
3736 return name ? name : "<unknown>";
3743 * g_signal_accumulator_true_handled:
3744 * @ihint: standard #GSignalAccumulator parameter
3745 * @return_accu: standard #GSignalAccumulator parameter
3746 * @handler_return: standard #GSignalAccumulator parameter
3747 * @dummy: standard #GSignalAccumulator parameter
3749 * A predefined #GSignalAccumulator for signals that return a
3750 * boolean values. The behavior that this accumulator gives is
3751 * that a return of %TRUE stops the signal emission: no further
3752 * callbacks will be invoked, while a return of %FALSE allows
3753 * the emission to continue. The idea here is that a %TRUE return
3754 * indicates that the callback handled the signal, and no further
3755 * handling is needed.
3759 * Returns: standard #GSignalAccumulator result
3762 g_signal_accumulator_true_handled (GSignalInvocationHint *ihint,
3763 GValue *return_accu,
3764 const GValue *handler_return,
3767 gboolean continue_emission;
3768 gboolean signal_handled;
3770 signal_handled = g_value_get_boolean (handler_return);
3771 g_value_set_boolean (return_accu, signal_handled);
3772 continue_emission = !signal_handled;
3774 return continue_emission;
3778 * g_signal_accumulator_first_wins:
3779 * @ihint: standard #GSignalAccumulator parameter
3780 * @return_accu: standard #GSignalAccumulator parameter
3781 * @handler_return: standard #GSignalAccumulator parameter
3782 * @dummy: standard #GSignalAccumulator parameter
3784 * A predefined #GSignalAccumulator for signals intended to be used as a
3785 * hook for application code to provide a particular value. Usually
3786 * only one such value is desired and multiple handlers for the same
3787 * signal don't make much sense (except for the case of the default
3788 * handler defined in the class structure, in which case you will
3789 * usually want the signal connection to override the class handler).
3791 * This accumulator will use the return value from the first signal
3792 * handler that is run as the return value for the signal and not run
3793 * any further handlers (ie: the first handler "wins").
3795 * Returns: standard #GSignalAccumulator result
3800 g_signal_accumulator_first_wins (GSignalInvocationHint *ihint,
3801 GValue *return_accu,
3802 const GValue *handler_return,
3805 g_value_copy (handler_return, return_accu);