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 (guint signal_id,
1738 GType instance_type,
1739 GSignalCVaMarshaller va_marshaller)
1743 g_return_if_fail (signal_id > 0);
1744 g_return_if_fail (va_marshaller != NULL);
1747 node = LOOKUP_SIGNAL_NODE (signal_id);
1750 node->va_marshaller = va_marshaller;
1751 if (node->class_closure_bsa)
1753 ClassClosure *cc = g_bsearch_array_get_nth (node->class_closure_bsa, &g_class_closure_bconfig, 0);
1754 if (cc->closure->marshal == node->c_marshaller)
1755 _g_closure_set_va_marshal (cc->closure, va_marshaller);
1758 node->single_va_closure_is_valid = FALSE;
1766 * g_signal_new_valist:
1767 * @signal_name: the name for the signal
1768 * @itype: the type this signal pertains to. It will also pertain to
1769 * types which are derived from this type.
1770 * @signal_flags: a combination of #GSignalFlags specifying detail of when
1771 * the default handler is to be invoked. You should at least specify
1772 * %G_SIGNAL_RUN_FIRST or %G_SIGNAL_RUN_LAST.
1773 * @class_closure: The closure to invoke on signal emission; may be %NULL.
1774 * @accumulator: the accumulator for this signal; may be %NULL.
1775 * @accu_data: user data for the @accumulator.
1776 * @c_marshaller: (allow-none): the function to translate arrays of parameter
1777 * values to signal emissions into C language callback invocations or %NULL.
1778 * @return_type: the type of return value, or #G_TYPE_NONE for a signal
1779 * without a return value.
1780 * @n_params: the number of parameter types in @args.
1781 * @args: va_list of #GType, one for each parameter.
1783 * Creates a new signal. (This is usually done in the class initializer.)
1785 * See g_signal_new() for details on allowed signal names.
1787 * If c_marshaller is %NULL, g_cclosure_marshal_generic() will be used as
1788 * the marshaller for this signal.
1790 * Returns: the signal id
1793 g_signal_new_valist (const gchar *signal_name,
1795 GSignalFlags signal_flags,
1796 GClosure *class_closure,
1797 GSignalAccumulator accumulator,
1799 GSignalCMarshaller c_marshaller,
1810 param_types = g_new (GType, n_params);
1812 for (i = 0; i < n_params; i++)
1813 param_types[i] = va_arg (args, GType);
1818 signal_id = g_signal_newv (signal_name, itype, signal_flags,
1819 class_closure, accumulator, accu_data, c_marshaller,
1820 return_type, n_params, param_types);
1821 g_free (param_types);
1827 signal_destroy_R (SignalNode *signal_node)
1829 SignalNode node = *signal_node;
1831 signal_node->destroyed = TRUE;
1833 /* reentrancy caution, zero out real contents first */
1834 signal_node->single_va_closure_is_valid = FALSE;
1835 signal_node->n_params = 0;
1836 signal_node->param_types = NULL;
1837 signal_node->return_type = 0;
1838 signal_node->class_closure_bsa = NULL;
1839 signal_node->accumulator = NULL;
1840 signal_node->c_marshaller = NULL;
1841 signal_node->va_marshaller = NULL;
1842 signal_node->emission_hooks = NULL;
1844 #ifdef G_ENABLE_DEBUG
1845 /* check current emissions */
1849 for (emission = g_emissions; emission; emission = emission->next)
1850 if (emission->ihint.signal_id == node.signal_id)
1851 g_critical (G_STRLOC ": signal \"%s\" being destroyed is currently in emission (instance '%p')",
1852 node.name, emission->instance);
1856 /* free contents that need to
1859 g_free (node.param_types);
1860 if (node.class_closure_bsa)
1864 for (i = 0; i < node.class_closure_bsa->n_nodes; i++)
1866 ClassClosure *cc = g_bsearch_array_get_nth (node.class_closure_bsa, &g_class_closure_bconfig, i);
1868 g_closure_unref (cc->closure);
1870 g_bsearch_array_free (node.class_closure_bsa, &g_class_closure_bconfig);
1872 g_free (node.accumulator);
1873 if (node.emission_hooks)
1875 g_hook_list_clear (node.emission_hooks);
1876 g_free (node.emission_hooks);
1882 * g_signal_override_class_closure:
1883 * @signal_id: the signal id
1884 * @instance_type: the instance type on which to override the class closure
1886 * @class_closure: the closure.
1888 * Overrides the class closure (i.e. the default handler) for the given signal
1889 * for emissions on instances of @instance_type. @instance_type must be derived
1890 * from the type to which the signal belongs.
1892 * See g_signal_chain_from_overridden() and
1893 * g_signal_chain_from_overridden_handler() for how to chain up to the
1894 * parent class closure from inside the overridden one.
1897 g_signal_override_class_closure (guint signal_id,
1898 GType instance_type,
1899 GClosure *class_closure)
1903 g_return_if_fail (signal_id > 0);
1904 g_return_if_fail (class_closure != NULL);
1907 node = LOOKUP_SIGNAL_NODE (signal_id);
1908 node_check_deprecated (node);
1909 if (!g_type_is_a (instance_type, node->itype))
1910 g_warning ("%s: type '%s' cannot be overridden for signal id '%u'", G_STRLOC, type_debug_name (instance_type), signal_id);
1913 ClassClosure *cc = signal_find_class_closure (node, instance_type);
1915 if (cc && cc->instance_type == instance_type)
1916 g_warning ("%s: type '%s' is already overridden for signal id '%u'", G_STRLOC, type_debug_name (instance_type), signal_id);
1918 signal_add_class_closure (node, instance_type, class_closure);
1924 * g_signal_override_class_handler:
1925 * @signal_name: the name for the signal
1926 * @instance_type: the instance type on which to override the class handler
1928 * @class_handler: the handler.
1930 * Overrides the class closure (i.e. the default handler) for the
1931 * given signal for emissions on instances of @instance_type with
1932 * callback @class_handler. @instance_type must be derived from the
1933 * type to which the signal belongs.
1935 * See g_signal_chain_from_overridden() and
1936 * g_signal_chain_from_overridden_handler() for how to chain up to the
1937 * parent class closure from inside the overridden one.
1942 g_signal_override_class_handler (const gchar *signal_name,
1943 GType instance_type,
1944 GCallback class_handler)
1948 g_return_if_fail (signal_name != NULL);
1949 g_return_if_fail (instance_type != G_TYPE_NONE);
1950 g_return_if_fail (class_handler != NULL);
1952 signal_id = g_signal_lookup (signal_name, instance_type);
1955 g_signal_override_class_closure (signal_id, instance_type,
1956 g_cclosure_new (class_handler, NULL, NULL));
1958 g_warning ("%s: signal name '%s' is invalid for type id '%"G_GSIZE_FORMAT"'",
1959 G_STRLOC, signal_name, instance_type);
1964 * g_signal_chain_from_overridden:
1965 * @instance_and_params: (array) the argument list of the signal emission.
1966 * The first element in the array is a #GValue for the instance the signal
1967 * is being emitted on. The rest are any arguments to be passed to the signal.
1968 * @return_value: Location for the return value.
1970 * Calls the original class closure of a signal. This function should only
1971 * be called from an overridden class closure; see
1972 * g_signal_override_class_closure() and
1973 * g_signal_override_class_handler().
1976 g_signal_chain_from_overridden (const GValue *instance_and_params,
1977 GValue *return_value)
1979 GType chain_type = 0, restore_type = 0;
1980 Emission *emission = NULL;
1981 GClosure *closure = NULL;
1985 g_return_if_fail (instance_and_params != NULL);
1986 instance = g_value_peek_pointer (instance_and_params);
1987 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
1990 emission = emission_find_innermost (instance);
1993 SignalNode *node = LOOKUP_SIGNAL_NODE (emission->ihint.signal_id);
1995 g_assert (node != NULL); /* paranoid */
1997 /* we should probably do the same parameter checks as g_signal_emit() here.
1999 if (emission->chain_type != G_TYPE_NONE)
2001 ClassClosure *cc = signal_find_class_closure (node, emission->chain_type);
2003 g_assert (cc != NULL); /* closure currently in call stack */
2005 n_params = node->n_params;
2006 restore_type = cc->instance_type;
2007 cc = signal_find_class_closure (node, g_type_parent (cc->instance_type));
2008 if (cc && cc->instance_type != restore_type)
2010 closure = cc->closure;
2011 chain_type = cc->instance_type;
2015 g_warning ("%s: signal id '%u' cannot be chained from current emission stage for instance '%p'", G_STRLOC, node->signal_id, instance);
2018 g_warning ("%s: no signal is currently being emitted for instance '%p'", G_STRLOC, instance);
2022 emission->chain_type = chain_type;
2024 g_closure_invoke (closure,
2027 instance_and_params,
2030 emission->chain_type = restore_type;
2036 * g_signal_chain_from_overridden_handler: (skip)
2037 * @instance: the instance the signal is being emitted on.
2038 * @...: parameters to be passed to the parent class closure, followed by a
2039 * location for the return value. If the return type of the signal
2040 * is #G_TYPE_NONE, the return value location can be omitted.
2042 * Calls the original class closure of a signal. This function should
2043 * only be called from an overridden class closure; see
2044 * g_signal_override_class_closure() and
2045 * g_signal_override_class_handler().
2050 g_signal_chain_from_overridden_handler (gpointer instance,
2053 GType chain_type = 0, restore_type = 0;
2054 Emission *emission = NULL;
2055 GClosure *closure = NULL;
2059 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
2062 emission = emission_find_innermost (instance);
2065 node = LOOKUP_SIGNAL_NODE (emission->ihint.signal_id);
2067 g_assert (node != NULL); /* paranoid */
2069 /* we should probably do the same parameter checks as g_signal_emit() here.
2071 if (emission->chain_type != G_TYPE_NONE)
2073 ClassClosure *cc = signal_find_class_closure (node, emission->chain_type);
2075 g_assert (cc != NULL); /* closure currently in call stack */
2077 n_params = node->n_params;
2078 restore_type = cc->instance_type;
2079 cc = signal_find_class_closure (node, g_type_parent (cc->instance_type));
2080 if (cc && cc->instance_type != restore_type)
2082 closure = cc->closure;
2083 chain_type = cc->instance_type;
2087 g_warning ("%s: signal id '%u' cannot be chained from current emission stage for instance '%p'", G_STRLOC, node->signal_id, instance);
2090 g_warning ("%s: no signal is currently being emitted for instance '%p'", G_STRLOC, instance);
2094 GValue *instance_and_params;
2095 GType signal_return_type;
2096 GValue *param_values;
2100 va_start (var_args, instance);
2102 signal_return_type = node->return_type;
2103 instance_and_params = g_alloca (sizeof (GValue) * (n_params + 1));
2104 memset (instance_and_params, 0, sizeof (GValue) * (n_params + 1));
2105 param_values = instance_and_params + 1;
2107 for (i = 0; i < node->n_params; i++)
2110 GType ptype = node->param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE;
2111 gboolean static_scope = node->param_types[i] & G_SIGNAL_TYPE_STATIC_SCOPE;
2114 G_VALUE_COLLECT_INIT (param_values + i, ptype,
2116 static_scope ? G_VALUE_NOCOPY_CONTENTS : 0,
2120 g_warning ("%s: %s", G_STRLOC, error);
2123 /* we purposely leak the value here, it might not be
2124 * in a sane state if an error condition occoured
2127 g_value_unset (param_values + i);
2136 instance_and_params->g_type = 0;
2137 g_value_init_from_instance (instance_and_params, instance);
2140 emission->chain_type = chain_type;
2143 if (signal_return_type == G_TYPE_NONE)
2145 g_closure_invoke (closure,
2148 instance_and_params,
2153 GValue return_value = G_VALUE_INIT;
2154 gchar *error = NULL;
2155 GType rtype = signal_return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE;
2156 gboolean static_scope = signal_return_type & G_SIGNAL_TYPE_STATIC_SCOPE;
2158 g_value_init (&return_value, rtype);
2160 g_closure_invoke (closure,
2163 instance_and_params,
2166 G_VALUE_LCOPY (&return_value,
2168 static_scope ? G_VALUE_NOCOPY_CONTENTS : 0,
2172 g_value_unset (&return_value);
2176 g_warning ("%s: %s", G_STRLOC, error);
2179 /* we purposely leak the value here, it might not be
2180 * in a sane state if an error condition occurred
2185 for (i = 0; i < n_params; i++)
2186 g_value_unset (param_values + i);
2187 g_value_unset (instance_and_params);
2192 emission->chain_type = restore_type;
2198 * g_signal_get_invocation_hint:
2199 * @instance: (type GObject.Object): the instance to query
2201 * Returns the invocation hint of the innermost signal emission of instance.
2203 * Returns: (transfer none): the invocation hint of the innermost signal emission.
2205 GSignalInvocationHint*
2206 g_signal_get_invocation_hint (gpointer instance)
2208 Emission *emission = NULL;
2210 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), NULL);
2213 emission = emission_find_innermost (instance);
2216 return emission ? &emission->ihint : NULL;
2220 * g_signal_connect_closure_by_id:
2221 * @instance: (type GObject.Object): the instance to connect to.
2222 * @signal_id: the id of the signal.
2223 * @detail: the detail.
2224 * @closure: the closure to connect.
2225 * @after: whether the handler should be called before or after the
2226 * default handler of the signal.
2228 * Connects a closure to a signal for a particular object.
2230 * Returns: the handler id (always greater than 0 for successful connections)
2233 g_signal_connect_closure_by_id (gpointer instance,
2240 gulong handler_seq_no = 0;
2242 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
2243 g_return_val_if_fail (signal_id > 0, 0);
2244 g_return_val_if_fail (closure != NULL, 0);
2247 node = LOOKUP_SIGNAL_NODE (signal_id);
2250 if (detail && !(node->flags & G_SIGNAL_DETAILED))
2251 g_warning ("%s: signal id '%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
2252 else if (!g_type_is_a (G_TYPE_FROM_INSTANCE (instance), node->itype))
2253 g_warning ("%s: signal id '%u' is invalid for instance '%p'", G_STRLOC, signal_id, instance);
2256 Handler *handler = handler_new (after);
2258 handler_seq_no = handler->sequential_number;
2259 handler->detail = detail;
2260 handler->closure = g_closure_ref (closure);
2261 g_closure_sink (closure);
2262 add_invalid_closure_notify (handler, instance);
2263 handler_insert (signal_id, instance, handler);
2264 if (node->c_marshaller && G_CLOSURE_NEEDS_MARSHAL (closure))
2266 g_closure_set_marshal (closure, node->c_marshaller);
2267 if (node->va_marshaller)
2268 _g_closure_set_va_marshal (closure, node->va_marshaller);
2273 g_warning ("%s: signal id '%u' is invalid for instance '%p'", G_STRLOC, signal_id, instance);
2276 return handler_seq_no;
2280 * g_signal_connect_closure:
2281 * @instance: (type GObject.Object): the instance to connect to.
2282 * @detailed_signal: a string of the form "signal-name::detail".
2283 * @closure: the closure to connect.
2284 * @after: whether the handler should be called before or after the
2285 * default handler of the signal.
2287 * Connects a closure to a signal for a particular object.
2289 * Returns: the handler id (always greater than 0 for successful connections)
2292 g_signal_connect_closure (gpointer instance,
2293 const gchar *detailed_signal,
2298 gulong handler_seq_no = 0;
2302 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
2303 g_return_val_if_fail (detailed_signal != NULL, 0);
2304 g_return_val_if_fail (closure != NULL, 0);
2307 itype = G_TYPE_FROM_INSTANCE (instance);
2308 signal_id = signal_parse_name (detailed_signal, itype, &detail, TRUE);
2311 SignalNode *node = LOOKUP_SIGNAL_NODE (signal_id);
2313 if (detail && !(node->flags & G_SIGNAL_DETAILED))
2314 g_warning ("%s: signal '%s' does not support details", G_STRLOC, detailed_signal);
2315 else if (!g_type_is_a (itype, node->itype))
2316 g_warning ("%s: signal '%s' is invalid for instance '%p' of type '%s'",
2317 G_STRLOC, detailed_signal, instance, g_type_name (itype));
2320 Handler *handler = handler_new (after);
2322 handler_seq_no = handler->sequential_number;
2323 handler->detail = detail;
2324 handler->closure = g_closure_ref (closure);
2325 g_closure_sink (closure);
2326 add_invalid_closure_notify (handler, instance);
2327 handler_insert (signal_id, instance, handler);
2328 if (node->c_marshaller && G_CLOSURE_NEEDS_MARSHAL (handler->closure))
2330 g_closure_set_marshal (handler->closure, node->c_marshaller);
2331 if (node->va_marshaller)
2332 _g_closure_set_va_marshal (handler->closure, node->va_marshaller);
2337 g_warning ("%s: signal '%s' is invalid for instance '%p' of type '%s'",
2338 G_STRLOC, detailed_signal, instance, g_type_name (itype));
2341 return handler_seq_no;
2345 node_check_deprecated (const SignalNode *node)
2347 static const gchar * g_enable_diagnostic = NULL;
2349 if (G_UNLIKELY (!g_enable_diagnostic))
2351 g_enable_diagnostic = g_getenv ("G_ENABLE_DIAGNOSTIC");
2352 if (!g_enable_diagnostic)
2353 g_enable_diagnostic = "0";
2356 if (g_enable_diagnostic[0] == '1')
2358 if (node->flags & G_SIGNAL_DEPRECATED)
2360 g_warning ("The signal %s::%s is deprecated and shouldn't be used "
2361 "anymore. It will be removed in a future version.",
2362 type_debug_name (node->itype), node->name);
2368 * g_signal_connect_data:
2369 * @instance: (type GObject.Object): the instance to connect to.
2370 * @detailed_signal: a string of the form "signal-name::detail".
2371 * @c_handler: the #GCallback to connect.
2372 * @data: data to pass to @c_handler calls.
2373 * @destroy_data: a #GClosureNotify for @data.
2374 * @connect_flags: a combination of #GConnectFlags.
2376 * Connects a #GCallback function to a signal for a particular object. Similar
2377 * to g_signal_connect(), but allows to provide a #GClosureNotify for the data
2378 * which will be called when the signal handler is disconnected and no longer
2379 * used. Specify @connect_flags if you need `..._after()` or
2380 * `..._swapped()` variants of this function.
2382 * Returns: the handler id (always greater than 0 for successful connections)
2385 g_signal_connect_data (gpointer instance,
2386 const gchar *detailed_signal,
2387 GCallback c_handler,
2389 GClosureNotify destroy_data,
2390 GConnectFlags connect_flags)
2393 gulong handler_seq_no = 0;
2396 gboolean swapped, after;
2398 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
2399 g_return_val_if_fail (detailed_signal != NULL, 0);
2400 g_return_val_if_fail (c_handler != NULL, 0);
2402 swapped = (connect_flags & G_CONNECT_SWAPPED) != FALSE;
2403 after = (connect_flags & G_CONNECT_AFTER) != FALSE;
2406 itype = G_TYPE_FROM_INSTANCE (instance);
2407 signal_id = signal_parse_name (detailed_signal, itype, &detail, TRUE);
2410 SignalNode *node = LOOKUP_SIGNAL_NODE (signal_id);
2412 node_check_deprecated (node);
2414 if (detail && !(node->flags & G_SIGNAL_DETAILED))
2415 g_warning ("%s: signal '%s' does not support details", G_STRLOC, detailed_signal);
2416 else if (!g_type_is_a (itype, node->itype))
2417 g_warning ("%s: signal '%s' is invalid for instance '%p' of type '%s'",
2418 G_STRLOC, detailed_signal, instance, g_type_name (itype));
2421 Handler *handler = handler_new (after);
2423 handler_seq_no = handler->sequential_number;
2424 handler->detail = detail;
2425 handler->closure = g_closure_ref ((swapped ? g_cclosure_new_swap : g_cclosure_new) (c_handler, data, destroy_data));
2426 g_closure_sink (handler->closure);
2427 handler_insert (signal_id, instance, handler);
2428 if (node->c_marshaller && G_CLOSURE_NEEDS_MARSHAL (handler->closure))
2430 g_closure_set_marshal (handler->closure, node->c_marshaller);
2431 if (node->va_marshaller)
2432 _g_closure_set_va_marshal (handler->closure, node->va_marshaller);
2437 g_warning ("%s: signal '%s' is invalid for instance '%p' of type '%s'",
2438 G_STRLOC, detailed_signal, instance, g_type_name (itype));
2441 return handler_seq_no;
2445 * g_signal_handler_block:
2446 * @instance: (type GObject.Object): The instance to block the signal handler of.
2447 * @handler_id: Handler id of the handler to be blocked.
2449 * Blocks a handler of an instance so it will not be called during any
2450 * signal emissions unless it is unblocked again. Thus "blocking" a
2451 * signal handler means to temporarily deactive it, a signal handler
2452 * has to be unblocked exactly the same amount of times it has been
2453 * blocked before to become active again.
2455 * The @handler_id has to be a valid signal handler id, connected to a
2456 * signal of @instance.
2459 g_signal_handler_block (gpointer instance,
2464 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
2465 g_return_if_fail (handler_id > 0);
2468 handler = handler_lookup (instance, handler_id, NULL, NULL);
2471 #ifndef G_DISABLE_CHECKS
2472 if (handler->block_count >= HANDLER_MAX_BLOCK_COUNT - 1)
2473 g_error (G_STRLOC ": handler block_count overflow, %s", REPORT_BUG);
2475 handler->block_count += 1;
2478 g_warning ("%s: instance '%p' has no handler with id '%lu'", G_STRLOC, instance, handler_id);
2483 * g_signal_handler_unblock:
2484 * @instance: (type GObject.Object): The instance to unblock the signal handler of.
2485 * @handler_id: Handler id of the handler to be unblocked.
2487 * Undoes the effect of a previous g_signal_handler_block() call. A
2488 * blocked handler is skipped during signal emissions and will not be
2489 * invoked, unblocking it (for exactly the amount of times it has been
2490 * blocked before) reverts its "blocked" state, so the handler will be
2491 * recognized by the signal system and is called upon future or
2492 * currently ongoing signal emissions (since the order in which
2493 * handlers are called during signal emissions is deterministic,
2494 * whether the unblocked handler in question is called as part of a
2495 * currently ongoing emission depends on how far that emission has
2498 * The @handler_id has to be a valid id of a signal handler that is
2499 * connected to a signal of @instance and is currently blocked.
2502 g_signal_handler_unblock (gpointer instance,
2507 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
2508 g_return_if_fail (handler_id > 0);
2511 handler = handler_lookup (instance, handler_id, NULL, NULL);
2514 if (handler->block_count)
2515 handler->block_count -= 1;
2517 g_warning (G_STRLOC ": handler '%lu' of instance '%p' is not blocked", handler_id, instance);
2520 g_warning ("%s: instance '%p' has no handler with id '%lu'", G_STRLOC, instance, handler_id);
2525 * g_signal_handler_disconnect:
2526 * @instance: (type GObject.Object): The instance to remove the signal handler from.
2527 * @handler_id: Handler id of the handler to be disconnected.
2529 * Disconnects a handler from an instance so it will not be called during
2530 * any future or currently ongoing emissions of the signal it has been
2531 * connected to. The @handler_id becomes invalid and may be reused.
2533 * The @handler_id has to be a valid signal handler id, connected to a
2534 * signal of @instance.
2537 g_signal_handler_disconnect (gpointer instance,
2543 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
2544 g_return_if_fail (handler_id > 0);
2547 handler = handler_lookup (instance, handler_id, NULL, &signal_id);
2550 handler->sequential_number = 0;
2551 handler->block_count = 1;
2552 remove_invalid_closure_notify (handler, instance);
2553 handler_unref_R (signal_id, instance, handler);
2556 g_warning ("%s: instance '%p' has no handler with id '%lu'", G_STRLOC, instance, handler_id);
2561 * g_signal_handler_is_connected:
2562 * @instance: (type GObject.Object): The instance where a signal handler is sought.
2563 * @handler_id: the handler id.
2565 * Returns whether @handler_id is the id of a handler connected to @instance.
2567 * Returns: whether @handler_id identifies a handler connected to @instance.
2570 g_signal_handler_is_connected (gpointer instance,
2576 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), FALSE);
2579 handler = handler_lookup (instance, handler_id, NULL, NULL);
2580 connected = handler != NULL;
2587 * g_signal_handlers_destroy:
2588 * @instance: (type GObject.Object): The instance whose signal handlers are destroyed
2590 * Destroy all signal handlers of a type instance. This function is
2591 * an implementation detail of the #GObject dispose implementation,
2592 * and should not be used outside of the type system.
2595 g_signal_handlers_destroy (gpointer instance)
2597 GBSearchArray *hlbsa;
2599 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
2602 hlbsa = g_hash_table_lookup (g_handler_list_bsa_ht, instance);
2607 /* reentrancy caution, delete instance trace first */
2608 g_hash_table_remove (g_handler_list_bsa_ht, instance);
2610 for (i = 0; i < hlbsa->n_nodes; i++)
2612 HandlerList *hlist = g_bsearch_array_get_nth (hlbsa, &g_signal_hlbsa_bconfig, i);
2613 Handler *handler = hlist->handlers;
2617 Handler *tmp = handler;
2619 handler = tmp->next;
2620 tmp->block_count = 1;
2621 /* cruel unlink, this works because _all_ handlers vanish */
2624 if (tmp->sequential_number)
2626 remove_invalid_closure_notify (tmp, instance);
2627 tmp->sequential_number = 0;
2628 handler_unref_R (0, NULL, tmp);
2632 g_bsearch_array_free (hlbsa, &g_signal_hlbsa_bconfig);
2638 * g_signal_handler_find:
2639 * @instance: (type GObject.Object): The instance owning the signal handler to be found.
2640 * @mask: Mask indicating which of @signal_id, @detail, @closure, @func
2641 * and/or @data the handler has to match.
2642 * @signal_id: Signal the handler has to be connected to.
2643 * @detail: Signal detail the handler has to be connected to.
2644 * @closure: (allow-none): The closure the handler will invoke.
2645 * @func: The C closure callback of the handler (useless for non-C closures).
2646 * @data: The closure data of the handler's closure.
2648 * Finds the first signal handler that matches certain selection criteria.
2649 * The criteria mask is passed as an OR-ed combination of #GSignalMatchType
2650 * flags, and the criteria values are passed as arguments.
2651 * The match @mask has to be non-0 for successful matches.
2652 * If no handler was found, 0 is returned.
2654 * Returns: A valid non-0 signal handler id for a successful match.
2657 g_signal_handler_find (gpointer instance,
2658 GSignalMatchType mask,
2665 gulong handler_seq_no = 0;
2667 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
2668 g_return_val_if_fail ((mask & ~G_SIGNAL_MATCH_MASK) == 0, 0);
2670 if (mask & G_SIGNAL_MATCH_MASK)
2672 HandlerMatch *mlist;
2675 mlist = handlers_find (instance, mask, signal_id, detail, closure, func, data, TRUE);
2678 handler_seq_no = mlist->handler->sequential_number;
2679 handler_match_free1_R (mlist, instance);
2684 return handler_seq_no;
2688 signal_handlers_foreach_matched_R (gpointer instance,
2689 GSignalMatchType mask,
2695 void (*callback) (gpointer instance,
2696 gulong handler_seq_no))
2698 HandlerMatch *mlist;
2699 guint n_handlers = 0;
2701 mlist = handlers_find (instance, mask, signal_id, detail, closure, func, data, FALSE);
2705 if (mlist->handler->sequential_number)
2708 callback (instance, mlist->handler->sequential_number);
2711 mlist = handler_match_free1_R (mlist, instance);
2718 * g_signal_handlers_block_matched:
2719 * @instance: (type GObject.Object): The instance to block handlers from.
2720 * @mask: Mask indicating which of @signal_id, @detail, @closure, @func
2721 * and/or @data the handlers have to match.
2722 * @signal_id: Signal the handlers have to be connected to.
2723 * @detail: Signal detail the handlers have to be connected to.
2724 * @closure: (allow-none): The closure the handlers will invoke.
2725 * @func: The C closure callback of the handlers (useless for non-C closures).
2726 * @data: The closure data of the handlers' closures.
2728 * Blocks all handlers on an instance that match a certain selection criteria.
2729 * The criteria mask is passed as an OR-ed combination of #GSignalMatchType
2730 * flags, and the criteria values are passed as arguments.
2731 * Passing at least one of the %G_SIGNAL_MATCH_CLOSURE, %G_SIGNAL_MATCH_FUNC
2732 * or %G_SIGNAL_MATCH_DATA match flags is required for successful matches.
2733 * If no handlers were found, 0 is returned, the number of blocked handlers
2736 * Returns: The number of handlers that matched.
2739 g_signal_handlers_block_matched (gpointer instance,
2740 GSignalMatchType mask,
2747 guint n_handlers = 0;
2749 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
2750 g_return_val_if_fail ((mask & ~G_SIGNAL_MATCH_MASK) == 0, 0);
2752 if (mask & (G_SIGNAL_MATCH_CLOSURE | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA))
2755 n_handlers = signal_handlers_foreach_matched_R (instance, mask, signal_id, detail,
2756 closure, func, data,
2757 g_signal_handler_block);
2765 * g_signal_handlers_unblock_matched:
2766 * @instance: (type GObject.Object): The instance to unblock handlers from.
2767 * @mask: Mask indicating which of @signal_id, @detail, @closure, @func
2768 * and/or @data the handlers have to match.
2769 * @signal_id: Signal the handlers have to be connected to.
2770 * @detail: Signal detail the handlers have to be connected to.
2771 * @closure: (allow-none): The closure the handlers will invoke.
2772 * @func: The C closure callback of the handlers (useless for non-C closures).
2773 * @data: The closure data of the handlers' closures.
2775 * Unblocks all handlers on an instance that match a certain selection
2776 * criteria. The criteria mask is passed as an OR-ed combination of
2777 * #GSignalMatchType flags, and the criteria values are passed as arguments.
2778 * Passing at least one of the %G_SIGNAL_MATCH_CLOSURE, %G_SIGNAL_MATCH_FUNC
2779 * or %G_SIGNAL_MATCH_DATA match flags is required for successful matches.
2780 * If no handlers were found, 0 is returned, the number of unblocked handlers
2781 * otherwise. The match criteria should not apply to any handlers that are
2782 * not currently blocked.
2784 * Returns: The number of handlers that matched.
2787 g_signal_handlers_unblock_matched (gpointer instance,
2788 GSignalMatchType mask,
2795 guint n_handlers = 0;
2797 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
2798 g_return_val_if_fail ((mask & ~G_SIGNAL_MATCH_MASK) == 0, 0);
2800 if (mask & (G_SIGNAL_MATCH_CLOSURE | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA))
2803 n_handlers = signal_handlers_foreach_matched_R (instance, mask, signal_id, detail,
2804 closure, func, data,
2805 g_signal_handler_unblock);
2813 * g_signal_handlers_disconnect_matched:
2814 * @instance: (type GObject.Object): The instance to remove handlers from.
2815 * @mask: Mask indicating which of @signal_id, @detail, @closure, @func
2816 * and/or @data the handlers have to match.
2817 * @signal_id: Signal the handlers have to be connected to.
2818 * @detail: Signal detail the handlers have to be connected to.
2819 * @closure: (allow-none): The closure the handlers will invoke.
2820 * @func: The C closure callback of the handlers (useless for non-C closures).
2821 * @data: The closure data of the handlers' closures.
2823 * Disconnects all handlers on an instance that match a certain
2824 * selection criteria. The criteria mask is passed as an OR-ed
2825 * combination of #GSignalMatchType flags, and the criteria values are
2826 * passed as arguments. Passing at least one of the
2827 * %G_SIGNAL_MATCH_CLOSURE, %G_SIGNAL_MATCH_FUNC or
2828 * %G_SIGNAL_MATCH_DATA match flags is required for successful
2829 * matches. If no handlers were found, 0 is returned, the number of
2830 * disconnected handlers otherwise.
2832 * Returns: The number of handlers that matched.
2835 g_signal_handlers_disconnect_matched (gpointer instance,
2836 GSignalMatchType mask,
2843 guint n_handlers = 0;
2845 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
2846 g_return_val_if_fail ((mask & ~G_SIGNAL_MATCH_MASK) == 0, 0);
2848 if (mask & (G_SIGNAL_MATCH_CLOSURE | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA))
2851 n_handlers = signal_handlers_foreach_matched_R (instance, mask, signal_id, detail,
2852 closure, func, data,
2853 g_signal_handler_disconnect);
2861 * g_signal_has_handler_pending:
2862 * @instance: (type GObject.Object): the object whose signal handlers are sought.
2863 * @signal_id: the signal id.
2864 * @detail: the detail.
2865 * @may_be_blocked: whether blocked handlers should count as match.
2867 * Returns whether there are any handlers connected to @instance for the
2868 * given signal id and detail.
2870 * If @detail is 0 then it will only match handlers that were connected
2871 * without detail. If @detail is non-zero then it will match handlers
2872 * connected both without detail and with the given detail. This is
2873 * consistent with how a signal emitted with @detail would be delivered
2874 * to those handlers.
2876 * One example of when you might use this is when the arguments to the
2877 * signal are difficult to compute. A class implementor may opt to not
2878 * emit the signal if no one is attached anyway, thus saving the cost
2879 * of building the arguments.
2881 * Returns: %TRUE if a handler is connected to the signal, %FALSE
2885 g_signal_has_handler_pending (gpointer instance,
2888 gboolean may_be_blocked)
2890 HandlerMatch *mlist;
2891 gboolean has_pending;
2893 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), FALSE);
2894 g_return_val_if_fail (signal_id > 0, FALSE);
2899 SignalNode *node = LOOKUP_SIGNAL_NODE (signal_id);
2901 if (!(node->flags & G_SIGNAL_DETAILED))
2903 g_warning ("%s: signal id '%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
2908 mlist = handlers_find (instance,
2909 (G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | (may_be_blocked ? 0 : G_SIGNAL_MATCH_UNBLOCKED)),
2910 signal_id, detail, NULL, NULL, NULL, TRUE);
2914 handler_match_free1_R (mlist, instance);
2917 has_pending = FALSE;
2925 * @instance_and_params: (array): argument list for the signal emission.
2926 * The first element in the array is a #GValue for the instance the signal
2927 * is being emitted on. The rest are any arguments to be passed to the signal.
2928 * @signal_id: the signal id
2929 * @detail: the detail
2930 * @return_value: Location to store the return value of the signal emission.
2934 * Note that g_signal_emitv() doesn't change @return_value if no handlers are
2935 * connected, in contrast to g_signal_emit() and g_signal_emit_valist().
2938 g_signal_emitv (const GValue *instance_and_params,
2941 GValue *return_value)
2945 #ifdef G_ENABLE_DEBUG
2946 const GValue *param_values;
2950 g_return_if_fail (instance_and_params != NULL);
2951 instance = g_value_peek_pointer (instance_and_params);
2952 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
2953 g_return_if_fail (signal_id > 0);
2955 #ifdef G_ENABLE_DEBUG
2956 param_values = instance_and_params + 1;
2960 node = LOOKUP_SIGNAL_NODE (signal_id);
2961 if (!node || !g_type_is_a (G_TYPE_FROM_INSTANCE (instance), node->itype))
2963 g_warning ("%s: signal id '%u' is invalid for instance '%p'", G_STRLOC, signal_id, instance);
2967 #ifdef G_ENABLE_DEBUG
2968 if (detail && !(node->flags & G_SIGNAL_DETAILED))
2970 g_warning ("%s: signal id '%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
2974 for (i = 0; i < node->n_params; i++)
2975 if (!G_TYPE_CHECK_VALUE_TYPE (param_values + i, node->param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE))
2977 g_critical ("%s: value for '%s' parameter %u for signal \"%s\" is of type '%s'",
2979 type_debug_name (node->param_types[i]),
2982 G_VALUE_TYPE_NAME (param_values + i));
2986 if (node->return_type != G_TYPE_NONE)
2990 g_critical ("%s: return value '%s' for signal \"%s\" is (NULL)",
2992 type_debug_name (node->return_type),
2997 else if (!node->accumulator && !G_TYPE_CHECK_VALUE_TYPE (return_value, node->return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE))
2999 g_critical ("%s: return value '%s' for signal \"%s\" is of type '%s'",
3001 type_debug_name (node->return_type),
3003 G_VALUE_TYPE_NAME (return_value));
3009 return_value = NULL;
3010 #endif /* G_ENABLE_DEBUG */
3012 /* optimize NOP emissions */
3013 if (!node->single_va_closure_is_valid)
3014 node_update_single_va_closure (node);
3016 if (node->single_va_closure != NULL &&
3017 (node->single_va_closure == SINGLE_VA_CLOSURE_EMPTY_MAGIC ||
3018 _g_closure_is_void (node->single_va_closure, instance)))
3020 HandlerList* hlist = handler_list_lookup (node->signal_id, instance);
3021 if (hlist == NULL || hlist->handlers == NULL)
3023 /* nothing to do to emit this signal */
3025 /* g_printerr ("omitting emission of \"%s\"\n", node->name); */
3031 signal_emit_unlocked_R (node, detail, instance, return_value, instance_and_params);
3034 static inline gboolean
3035 accumulate (GSignalInvocationHint *ihint,
3036 GValue *return_accu,
3037 GValue *handler_return,
3038 SignalAccumulator *accumulator)
3040 gboolean continue_emission;
3045 continue_emission = accumulator->func (ihint, return_accu, handler_return, accumulator->data);
3046 g_value_reset (handler_return);
3048 return continue_emission;
3052 * g_signal_emit_valist: (skip)
3053 * @instance: the instance the signal is being emitted on.
3054 * @signal_id: the signal id
3055 * @detail: the detail
3056 * @var_args: a list of parameters to be passed to the signal, followed by a
3057 * location for the return value. If the return type of the signal
3058 * is #G_TYPE_NONE, the return value location can be omitted.
3062 * Note that g_signal_emit_valist() resets the return value to the default
3063 * if no handlers are connected, in contrast to g_signal_emitv().
3066 g_signal_emit_valist (gpointer instance,
3071 GValue *instance_and_params;
3072 GType signal_return_type;
3073 GValue *param_values;
3077 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
3078 g_return_if_fail (signal_id > 0);
3081 node = LOOKUP_SIGNAL_NODE (signal_id);
3082 if (!node || !g_type_is_a (G_TYPE_FROM_INSTANCE (instance), node->itype))
3084 g_warning ("%s: signal id '%u' is invalid for instance '%p'", G_STRLOC, signal_id, instance);
3088 #ifndef G_DISABLE_CHECKS
3089 if (detail && !(node->flags & G_SIGNAL_DETAILED))
3091 g_warning ("%s: signal id '%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
3095 #endif /* !G_DISABLE_CHECKS */
3097 if (!node->single_va_closure_is_valid)
3098 node_update_single_va_closure (node);
3100 if (node->single_va_closure != NULL)
3102 HandlerList* hlist = handler_list_lookup (node->signal_id, instance);
3103 Handler *fastpath_handler = NULL;
3105 GClosure *closure = NULL;
3106 gboolean fastpath = TRUE;
3107 GSignalFlags run_type = G_SIGNAL_RUN_FIRST;
3109 if (node->single_va_closure != SINGLE_VA_CLOSURE_EMPTY_MAGIC &&
3110 !_g_closure_is_void (node->single_va_closure, instance))
3112 if (_g_closure_supports_invoke_va (node->single_va_closure))
3114 closure = node->single_va_closure;
3115 if (node->single_va_closure_is_after)
3116 run_type = G_SIGNAL_RUN_LAST;
3118 run_type = G_SIGNAL_RUN_FIRST;
3124 for (l = hlist ? hlist->handlers : NULL; fastpath && l != NULL; l = l->next)
3126 if (!l->block_count &&
3127 (!l->detail || l->detail == detail))
3129 if (closure != NULL || !_g_closure_supports_invoke_va (l->closure))
3136 fastpath_handler = l;
3137 closure = l->closure;
3139 run_type = G_SIGNAL_RUN_LAST;
3141 run_type = G_SIGNAL_RUN_FIRST;
3146 if (fastpath && closure == NULL && node->return_type == G_TYPE_NONE)
3152 /* Don't allow no-recurse emission as we might have to restart, which means
3153 we will run multiple handlers and thus must ref all arguments */
3154 if (closure != NULL && (node->flags & (G_SIGNAL_NO_RECURSE)) != 0)
3159 SignalAccumulator *accumulator;
3161 GValue *return_accu, accu = G_VALUE_INIT;
3163 GType instance_type = G_TYPE_FROM_INSTANCE (instance);
3164 GValue emission_return = G_VALUE_INIT;
3165 GType rtype = node->return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE;
3166 gboolean static_scope = node->return_type & G_SIGNAL_TYPE_STATIC_SCOPE;
3168 signal_id = node->signal_id;
3169 accumulator = node->accumulator;
3170 if (rtype == G_TYPE_NONE)
3172 else if (accumulator)
3173 return_accu = &accu;
3175 return_accu = &emission_return;
3177 emission.instance = instance;
3178 emission.ihint.signal_id = signal_id;
3179 emission.ihint.detail = detail;
3180 emission.ihint.run_type = run_type;
3181 emission.state = EMISSION_RUN;
3182 emission.chain_type = instance_type;
3183 emission_push (&emission);
3185 if (fastpath_handler)
3186 handler_ref (fastpath_handler);
3190 TRACE(GOBJECT_SIGNAL_EMIT(signal_id, detail, instance, instance_type));
3192 if (rtype != G_TYPE_NONE)
3193 g_value_init (&emission_return, rtype);
3196 g_value_init (&accu, rtype);
3198 if (closure != NULL)
3200 g_object_ref (instance);
3201 _g_closure_invoke_va (closure,
3207 accumulate (&emission.ihint, &emission_return, &accu, accumulator);
3212 emission.chain_type = G_TYPE_NONE;
3213 emission_pop (&emission);
3215 if (fastpath_handler)
3216 handler_unref_R (signal_id, instance, fastpath_handler);
3221 g_value_unset (&accu);
3223 if (rtype != G_TYPE_NONE)
3225 gchar *error = NULL;
3226 for (i = 0; i < node->n_params; i++)
3228 GType ptype = node->param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE;
3229 G_VALUE_COLLECT_SKIP (ptype, var_args);
3232 G_VALUE_LCOPY (&emission_return,
3234 static_scope ? G_VALUE_NOCOPY_CONTENTS : 0,
3237 g_value_unset (&emission_return);
3240 g_warning ("%s: %s", G_STRLOC, error);
3242 /* we purposely leak the value here, it might not be
3243 * in a sane state if an error condition occurred
3248 TRACE(GOBJECT_SIGNAL_EMIT_END(signal_id, detail, instance, instance_type));
3250 if (closure != NULL)
3251 g_object_unref (instance);
3258 n_params = node->n_params;
3259 signal_return_type = node->return_type;
3260 instance_and_params = g_alloca (sizeof (GValue) * (n_params + 1));
3261 memset (instance_and_params, 0, sizeof (GValue) * (n_params + 1));
3262 param_values = instance_and_params + 1;
3264 for (i = 0; i < node->n_params; i++)
3267 GType ptype = node->param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE;
3268 gboolean static_scope = node->param_types[i] & G_SIGNAL_TYPE_STATIC_SCOPE;
3270 G_VALUE_COLLECT_INIT (param_values + i, ptype,
3272 static_scope ? G_VALUE_NOCOPY_CONTENTS : 0,
3276 g_warning ("%s: %s", G_STRLOC, error);
3279 /* we purposely leak the value here, it might not be
3280 * in a sane state if an error condition occoured
3283 g_value_unset (param_values + i);
3289 instance_and_params->g_type = 0;
3290 g_value_init_from_instance (instance_and_params, instance);
3291 if (signal_return_type == G_TYPE_NONE)
3292 signal_emit_unlocked_R (node, detail, instance, NULL, instance_and_params);
3295 GValue return_value = G_VALUE_INIT;
3296 gchar *error = NULL;
3297 GType rtype = signal_return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE;
3298 gboolean static_scope = signal_return_type & G_SIGNAL_TYPE_STATIC_SCOPE;
3300 g_value_init (&return_value, rtype);
3302 signal_emit_unlocked_R (node, detail, instance, &return_value, instance_and_params);
3304 G_VALUE_LCOPY (&return_value,
3306 static_scope ? G_VALUE_NOCOPY_CONTENTS : 0,
3309 g_value_unset (&return_value);
3312 g_warning ("%s: %s", G_STRLOC, error);
3315 /* we purposely leak the value here, it might not be
3316 * in a sane state if an error condition occurred
3320 for (i = 0; i < n_params; i++)
3321 g_value_unset (param_values + i);
3322 g_value_unset (instance_and_params);
3327 * @instance: (type GObject.Object): the instance the signal is being emitted on.
3328 * @signal_id: the signal id
3329 * @detail: the detail
3330 * @...: parameters to be passed to the signal, followed by a
3331 * location for the return value. If the return type of the signal
3332 * is #G_TYPE_NONE, the return value location can be omitted.
3336 * Note that g_signal_emit() resets the return value to the default
3337 * if no handlers are connected, in contrast to g_signal_emitv().
3340 g_signal_emit (gpointer instance,
3347 va_start (var_args, detail);
3348 g_signal_emit_valist (instance, signal_id, detail, var_args);
3353 * g_signal_emit_by_name:
3354 * @instance: (type GObject.Object): the instance the signal is being emitted on.
3355 * @detailed_signal: a string of the form "signal-name::detail".
3356 * @...: parameters to be passed to the signal, followed by a
3357 * location for the return value. If the return type of the signal
3358 * is #G_TYPE_NONE, the return value location can be omitted.
3362 * Note that g_signal_emit_by_name() resets the return value to the default
3363 * if no handlers are connected, in contrast to g_signal_emitv().
3366 g_signal_emit_by_name (gpointer instance,
3367 const gchar *detailed_signal,
3374 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
3375 g_return_if_fail (detailed_signal != NULL);
3377 itype = G_TYPE_FROM_INSTANCE (instance);
3380 signal_id = signal_parse_name (detailed_signal, itype, &detail, TRUE);
3387 va_start (var_args, detailed_signal);
3388 g_signal_emit_valist (instance, signal_id, detail, var_args);
3392 g_warning ("%s: signal name '%s' is invalid for instance '%p' of type '%s'",
3393 G_STRLOC, detailed_signal, instance, g_type_name (itype));
3397 signal_emit_unlocked_R (SignalNode *node,
3400 GValue *emission_return,
3401 const GValue *instance_and_params)
3403 SignalAccumulator *accumulator;
3405 GClosure *class_closure;
3407 Handler *handler_list = NULL;
3408 GValue *return_accu, accu = G_VALUE_INIT;
3410 gulong max_sequential_handler_number;
3411 gboolean return_value_altered = FALSE;
3413 TRACE(GOBJECT_SIGNAL_EMIT(node->signal_id, detail, instance, G_TYPE_FROM_INSTANCE (instance)));
3416 signal_id = node->signal_id;
3418 if (node->flags & G_SIGNAL_NO_RECURSE)
3420 Emission *node = emission_find (signal_id, detail, instance);
3424 node->state = EMISSION_RESTART;
3426 return return_value_altered;
3429 accumulator = node->accumulator;
3433 g_value_init (&accu, node->return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE);
3434 return_accu = &accu;
3438 return_accu = emission_return;
3439 emission.instance = instance;
3440 emission.ihint.signal_id = node->signal_id;
3441 emission.ihint.detail = detail;
3442 emission.ihint.run_type = 0;
3444 emission.chain_type = G_TYPE_NONE;
3445 emission_push (&emission);
3446 class_closure = signal_lookup_closure (node, instance);
3451 handler_unref_R (signal_id, instance, handler_list);
3452 max_sequential_handler_number = g_handler_sequential_number;
3453 hlist = handler_list_lookup (signal_id, instance);
3454 handler_list = hlist ? hlist->handlers : NULL;
3456 handler_ref (handler_list);
3458 emission.ihint.run_type = G_SIGNAL_RUN_FIRST;
3460 if ((node->flags & G_SIGNAL_RUN_FIRST) && class_closure)
3462 emission.state = EMISSION_RUN;
3464 emission.chain_type = G_TYPE_FROM_INSTANCE (instance);
3466 g_closure_invoke (class_closure,
3469 instance_and_params,
3471 if (!accumulate (&emission.ihint, emission_return, &accu, accumulator) &&
3472 emission.state == EMISSION_RUN)
3473 emission.state = EMISSION_STOP;
3475 emission.chain_type = G_TYPE_NONE;
3476 return_value_altered = TRUE;
3478 if (emission.state == EMISSION_STOP)
3480 else if (emission.state == EMISSION_RESTART)
3484 if (node->emission_hooks)
3486 gboolean need_destroy, was_in_call, may_recurse = TRUE;
3489 emission.state = EMISSION_HOOK;
3490 hook = g_hook_first_valid (node->emission_hooks, may_recurse);
3493 SignalHook *signal_hook = SIGNAL_HOOK (hook);
3495 if (!signal_hook->detail || signal_hook->detail == detail)
3497 GSignalEmissionHook hook_func = (GSignalEmissionHook) hook->func;
3499 was_in_call = G_HOOK_IN_CALL (hook);
3500 hook->flags |= G_HOOK_FLAG_IN_CALL;
3502 need_destroy = !hook_func (&emission.ihint, node->n_params + 1, instance_and_params, hook->data);
3505 hook->flags &= ~G_HOOK_FLAG_IN_CALL;
3507 g_hook_destroy_link (node->emission_hooks, hook);
3509 hook = g_hook_next_valid (node->emission_hooks, hook, may_recurse);
3512 if (emission.state == EMISSION_RESTART)
3518 Handler *handler = handler_list;
3520 emission.state = EMISSION_RUN;
3521 handler_ref (handler);
3528 handler_unref_R (signal_id, instance, handler_list);
3529 handler_list = handler;
3532 else if (!handler->block_count && (!handler->detail || handler->detail == detail) &&
3533 handler->sequential_number < max_sequential_handler_number)
3536 g_closure_invoke (handler->closure,
3539 instance_and_params,
3541 if (!accumulate (&emission.ihint, emission_return, &accu, accumulator) &&
3542 emission.state == EMISSION_RUN)
3543 emission.state = EMISSION_STOP;
3545 return_value_altered = TRUE;
3547 tmp = emission.state == EMISSION_RUN ? handler->next : NULL;
3550 tmp = handler->next;
3554 handler_unref_R (signal_id, instance, handler_list);
3555 handler_list = handler;
3560 if (emission.state == EMISSION_STOP)
3562 else if (emission.state == EMISSION_RESTART)
3566 emission.ihint.run_type = G_SIGNAL_RUN_LAST;
3568 if ((node->flags & G_SIGNAL_RUN_LAST) && class_closure)
3570 emission.state = EMISSION_RUN;
3572 emission.chain_type = G_TYPE_FROM_INSTANCE (instance);
3574 g_closure_invoke (class_closure,
3577 instance_and_params,
3579 if (!accumulate (&emission.ihint, emission_return, &accu, accumulator) &&
3580 emission.state == EMISSION_RUN)
3581 emission.state = EMISSION_STOP;
3583 emission.chain_type = G_TYPE_NONE;
3584 return_value_altered = TRUE;
3586 if (emission.state == EMISSION_STOP)
3588 else if (emission.state == EMISSION_RESTART)
3594 Handler *handler = handler_list;
3596 emission.state = EMISSION_RUN;
3597 handler_ref (handler);
3602 if (handler->after && !handler->block_count && (!handler->detail || handler->detail == detail) &&
3603 handler->sequential_number < max_sequential_handler_number)
3606 g_closure_invoke (handler->closure,
3609 instance_and_params,
3611 if (!accumulate (&emission.ihint, emission_return, &accu, accumulator) &&
3612 emission.state == EMISSION_RUN)
3613 emission.state = EMISSION_STOP;
3615 return_value_altered = TRUE;
3617 tmp = emission.state == EMISSION_RUN ? handler->next : NULL;
3620 tmp = handler->next;
3624 handler_unref_R (signal_id, instance, handler);
3629 if (emission.state == EMISSION_STOP)
3631 else if (emission.state == EMISSION_RESTART)
3637 emission.ihint.run_type = G_SIGNAL_RUN_CLEANUP;
3639 if ((node->flags & G_SIGNAL_RUN_CLEANUP) && class_closure)
3641 gboolean need_unset = FALSE;
3643 emission.state = EMISSION_STOP;
3645 emission.chain_type = G_TYPE_FROM_INSTANCE (instance);
3647 if (node->return_type != G_TYPE_NONE && !accumulator)
3649 g_value_init (&accu, node->return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE);
3652 g_closure_invoke (class_closure,
3653 node->return_type != G_TYPE_NONE ? &accu : NULL,
3655 instance_and_params,
3658 g_value_unset (&accu);
3660 emission.chain_type = G_TYPE_NONE;
3662 if (emission.state == EMISSION_RESTART)
3667 handler_unref_R (signal_id, instance, handler_list);
3669 emission_pop (&emission);
3672 g_value_unset (&accu);
3674 TRACE(GOBJECT_SIGNAL_EMIT_END(node->signal_id, detail, instance, G_TYPE_FROM_INSTANCE (instance)));
3676 return return_value_altered;
3680 add_invalid_closure_notify (Handler *handler,
3683 g_closure_add_invalidate_notifier (handler->closure, instance, invalid_closure_notify);
3684 handler->has_invalid_closure_notify = 1;
3688 remove_invalid_closure_notify (Handler *handler,
3691 if (handler->has_invalid_closure_notify)
3693 g_closure_remove_invalidate_notifier (handler->closure, instance, invalid_closure_notify);
3694 handler->has_invalid_closure_notify = 0;
3699 invalid_closure_notify (gpointer instance,
3707 handler = handler_lookup (instance, 0, closure, &signal_id);
3708 g_assert (handler->closure == closure);
3710 handler->sequential_number = 0;
3711 handler->block_count = 1;
3712 handler_unref_R (signal_id, instance, handler);
3718 type_debug_name (GType type)
3722 const char *name = g_type_name (type & ~G_SIGNAL_TYPE_STATIC_SCOPE);
3723 return name ? name : "<unknown>";
3730 * g_signal_accumulator_true_handled:
3731 * @ihint: standard #GSignalAccumulator parameter
3732 * @return_accu: standard #GSignalAccumulator parameter
3733 * @handler_return: standard #GSignalAccumulator parameter
3734 * @dummy: standard #GSignalAccumulator parameter
3736 * A predefined #GSignalAccumulator for signals that return a
3737 * boolean values. The behavior that this accumulator gives is
3738 * that a return of %TRUE stops the signal emission: no further
3739 * callbacks will be invoked, while a return of %FALSE allows
3740 * the emission to continue. The idea here is that a %TRUE return
3741 * indicates that the callback handled the signal, and no further
3742 * handling is needed.
3746 * Returns: standard #GSignalAccumulator result
3749 g_signal_accumulator_true_handled (GSignalInvocationHint *ihint,
3750 GValue *return_accu,
3751 const GValue *handler_return,
3754 gboolean continue_emission;
3755 gboolean signal_handled;
3757 signal_handled = g_value_get_boolean (handler_return);
3758 g_value_set_boolean (return_accu, signal_handled);
3759 continue_emission = !signal_handled;
3761 return continue_emission;
3765 * g_signal_accumulator_first_wins:
3766 * @ihint: standard #GSignalAccumulator parameter
3767 * @return_accu: standard #GSignalAccumulator parameter
3768 * @handler_return: standard #GSignalAccumulator parameter
3769 * @dummy: standard #GSignalAccumulator parameter
3771 * A predefined #GSignalAccumulator for signals intended to be used as a
3772 * hook for application code to provide a particular value. Usually
3773 * only one such value is desired and multiple handlers for the same
3774 * signal don't make much sense (except for the case of the default
3775 * handler defined in the class structure, in which case you will
3776 * usually want the signal connection to override the class handler).
3778 * This accumulator will use the return value from the first signal
3779 * handler that is run as the return value for the signal and not run
3780 * any further handlers (ie: the first handler "wins").
3782 * Returns: standard #GSignalAccumulator result
3787 g_signal_accumulator_first_wins (GSignalInvocationHint *ihint,
3788 GValue *return_accu,
3789 const GValue *handler_return,
3792 g_value_copy (handler_return, return_accu);