os/ossrv/glib/gobject/gsignal.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/* GObject - GLib Type, Object, Parameter and Signal Library
sl@0
     2
 * Copyright (C) 2000-2001 Red Hat, Inc.
sl@0
     3
 * Portions copyright (c) 2006-2009 Nokia Corporation.  All rights reserved.
sl@0
     4
 *
sl@0
     5
 * This library is free software; you can redistribute it and/or
sl@0
     6
 * modify it under the terms of the GNU Lesser General Public
sl@0
     7
 * License as published by the Free Software Foundation; either
sl@0
     8
 * version 2 of the License, or (at your option) any later version.
sl@0
     9
 *
sl@0
    10
 * This library is distributed in the hope that it will be useful,
sl@0
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
sl@0
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
sl@0
    13
 * Lesser General Public License for more details.
sl@0
    14
 *
sl@0
    15
 * You should have received a copy of the GNU Lesser General
sl@0
    16
 * Public License along with this library; if not, write to the
sl@0
    17
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
sl@0
    18
 * Boston, MA 02111-1307, USA.
sl@0
    19
 *
sl@0
    20
 * this code is based on the original GtkSignal implementation
sl@0
    21
 * for the Gtk+ library by Peter Mattis <petm@xcf.berkeley.edu>
sl@0
    22
 */
sl@0
    23
sl@0
    24
/*
sl@0
    25
 * MT safe
sl@0
    26
 */
sl@0
    27
sl@0
    28
#include "config.h"
sl@0
    29
sl@0
    30
#include <string.h>
sl@0
    31
#include <signal.h>
sl@0
    32
sl@0
    33
#include "gsignal.h"
sl@0
    34
#include "gbsearcharray.h"
sl@0
    35
#include "gvaluecollector.h"
sl@0
    36
#include "gvaluetypes.h"
sl@0
    37
#include "gboxed.h"
sl@0
    38
#include "gobject.h"
sl@0
    39
#include "genums.h"
sl@0
    40
#include "gobjectalias.h"
sl@0
    41
#ifdef __SYMBIAN32__
sl@0
    42
#include <glib_global.h>
sl@0
    43
#include "gobject_wsd.h"
sl@0
    44
#endif /* __SYMBIAN32__ */
sl@0
    45
sl@0
    46
/**
sl@0
    47
 * SECTION:signals
sl@0
    48
 * @short_description: A means for customization of object behaviour
sl@0
    49
 *     and a general purpose notification mechanism
sl@0
    50
 * @title: Signals
sl@0
    51
 *
sl@0
    52
 * The basic concept of the signal system is that of the
sl@0
    53
 * <emphasis>emission</emphasis> of a signal. Signals are introduced
sl@0
    54
 * per-type and are identified through strings.  Signals introduced
sl@0
    55
 * for a parent type are available in derived types as well, so
sl@0
    56
 * basically they are a per-type facility that is inherited.  A signal
sl@0
    57
 * emission mainly involves invocation of a certain set of callbacks
sl@0
    58
 * in precisely defined manner. There are two main categories of such
sl@0
    59
 * callbacks, per-object 
sl@0
    60
 * <footnote><para>Although signals can deal with any kind of instantiatable 
sl@0
    61
 * type, i'm referring to those types as "object types" in the following, 
sl@0
    62
 * simply because that is the context most users will encounter signals in.
sl@0
    63
 * </para></footnote>
sl@0
    64
 * ones and user provided ones.
sl@0
    65
 * The per-object callbacks are most often referred to as "object method
sl@0
    66
 * handler" or "default (signal) handler", while user provided callbacks are
sl@0
    67
 * usually just called "signal handler".
sl@0
    68
 * The object method handler is provided at signal creation time (this most
sl@0
    69
 * frequently happens at the end of an object class' creation), while user
sl@0
    70
 * provided handlers are frequently connected and disconnected to/from a certain
sl@0
    71
 * signal on certain object instances.
sl@0
    72
 *
sl@0
    73
 * A signal emission consists of five stages, unless prematurely stopped:
sl@0
    74
 * <variablelist>
sl@0
    75
 * <varlistentry><term></term><listitem><para>
sl@0
    76
 * 	1 - Invocation of the object method handler for %G_SIGNAL_RUN_FIRST signals
sl@0
    77
 * </para></listitem></varlistentry>
sl@0
    78
 * <varlistentry><term></term><listitem><para>
sl@0
    79
 * 	2 - Invocation of normal user-provided signal handlers (<emphasis>after</emphasis> flag %FALSE)
sl@0
    80
 * </para></listitem></varlistentry>
sl@0
    81
 * <varlistentry><term></term><listitem><para>
sl@0
    82
 * 	3 - Invocation of the object method handler for %G_SIGNAL_RUN_LAST signals
sl@0
    83
 * </para></listitem></varlistentry>
sl@0
    84
 * <varlistentry><term></term><listitem><para>
sl@0
    85
 * 	4 - Invocation of user provided signal handlers, connected with an <emphasis>after</emphasis> flag of %TRUE
sl@0
    86
 * </para></listitem></varlistentry>
sl@0
    87
 * <varlistentry><term></term><listitem><para>
sl@0
    88
 * 	5 - Invocation of the object method handler for %G_SIGNAL_RUN_CLEANUP signals
sl@0
    89
 * </para></listitem></varlistentry>
sl@0
    90
 * </variablelist>
sl@0
    91
 * The user-provided signal handlers are called in the order they were
sl@0
    92
 * connected in.
sl@0
    93
 * All handlers may prematurely stop a signal emission, and any number of
sl@0
    94
 * handlers may be connected, disconnected, blocked or unblocked during
sl@0
    95
 * a signal emission.
sl@0
    96
 * There are certain criteria for skipping user handlers in stages 2 and 4
sl@0
    97
 * of a signal emission.
sl@0
    98
 * First, user handlers may be <emphasis>blocked</emphasis>, blocked handlers are omitted
sl@0
    99
 * during callback invocation, to return from the "blocked" state, a
sl@0
   100
 * handler has to get unblocked exactly the same amount of times
sl@0
   101
 * it has been blocked before.
sl@0
   102
 * Second, upon emission of a %G_SIGNAL_DETAILED signal, an additional
sl@0
   103
 * "detail" argument passed in to g_signal_emit() has to match the detail
sl@0
   104
 * argument of the signal handler currently subject to invocation.
sl@0
   105
 * Specification of no detail argument for signal handlers (omission of the
sl@0
   106
 * detail part of the signal specification upon connection) serves as a
sl@0
   107
 * wildcard and matches any detail argument passed in to emission.
sl@0
   108
 */
sl@0
   109
sl@0
   110
sl@0
   111
#define REPORT_BUG      "please report occurrence circumstances to gtk-devel-list@gnome.org"
sl@0
   112
#ifdef	G_ENABLE_DEBUG
sl@0
   113
#define IF_DEBUG(debug_type, cond)	if ((_g_type_debug_flags & G_TYPE_DEBUG_ ## debug_type) || cond)
sl@0
   114
sl@0
   115
#if EMULATOR
sl@0
   116
sl@0
   117
PLS(g_trace_instance_signals,gsignal,volatile gpointer )
sl@0
   118
PLS(g_trap_instance_signals,gsignal,volatile gpointer )
sl@0
   119
sl@0
   120
#define g_trace_instance_signals (*FUNCTION_NAME(g_trace_instance_signals,gsignal)())
sl@0
   121
#define g_trap_instance_signals (*FUNCTION_NAME(g_trap_instance_signals,gsignal)())
sl@0
   122
sl@0
   123
#else
sl@0
   124
sl@0
   125
static volatile gpointer g_trace_instance_signals = NULL;
sl@0
   126
static volatile gpointer g_trap_instance_signals = NULL;
sl@0
   127
sl@0
   128
#endif /* EMULATOR */
sl@0
   129
#endif	/* G_ENABLE_DEBUG */
sl@0
   130
sl@0
   131
sl@0
   132
/* --- typedefs --- */
sl@0
   133
typedef struct _SignalNode   SignalNode;
sl@0
   134
typedef struct _SignalKey    SignalKey;
sl@0
   135
typedef struct _Emission     Emission;
sl@0
   136
typedef struct _Handler      Handler;
sl@0
   137
typedef struct _HandlerList  HandlerList;
sl@0
   138
typedef struct _HandlerMatch HandlerMatch;
sl@0
   139
typedef enum
sl@0
   140
{
sl@0
   141
  EMISSION_STOP,
sl@0
   142
  EMISSION_RUN,
sl@0
   143
  EMISSION_HOOK,
sl@0
   144
  EMISSION_RESTART
sl@0
   145
} EmissionState;
sl@0
   146
sl@0
   147
sl@0
   148
/* --- prototypes --- */
sl@0
   149
static inline guint		signal_id_lookup	(GQuark		  quark,
sl@0
   150
							 GType		  itype);
sl@0
   151
static	      void		signal_destroy_R	(SignalNode	 *signal_node);
sl@0
   152
static inline HandlerList*	handler_list_ensure	(guint		  signal_id,
sl@0
   153
							 gpointer	  instance);
sl@0
   154
static inline HandlerList*	handler_list_lookup	(guint		  signal_id,
sl@0
   155
							 gpointer	  instance);
sl@0
   156
static inline Handler*		handler_new		(gboolean	  after);
sl@0
   157
static	      void		handler_insert		(guint		  signal_id,
sl@0
   158
							 gpointer	  instance,
sl@0
   159
							 Handler	 *handler);
sl@0
   160
static	      Handler*		handler_lookup		(gpointer	  instance,
sl@0
   161
							 gulong		  handler_id,
sl@0
   162
							 guint		 *signal_id_p);
sl@0
   163
static inline HandlerMatch*	handler_match_prepend	(HandlerMatch	 *list,
sl@0
   164
							 Handler	 *handler,
sl@0
   165
							 guint		  signal_id);
sl@0
   166
static inline HandlerMatch*	handler_match_free1_R	(HandlerMatch	 *node,
sl@0
   167
							 gpointer	  instance);
sl@0
   168
static	      HandlerMatch*	handlers_find		(gpointer	  instance,
sl@0
   169
							 GSignalMatchType mask,
sl@0
   170
							 guint		  signal_id,
sl@0
   171
							 GQuark		  detail,
sl@0
   172
							 GClosure	 *closure,
sl@0
   173
							 gpointer	  func,
sl@0
   174
							 gpointer	  data,
sl@0
   175
							 gboolean	  one_and_only);
sl@0
   176
static inline void		handler_ref		(Handler	 *handler);
sl@0
   177
static inline void		handler_unref_R		(guint		  signal_id,
sl@0
   178
							 gpointer	  instance,
sl@0
   179
							 Handler	 *handler);
sl@0
   180
static gint			handler_lists_cmp	(gconstpointer	  node1,
sl@0
   181
							 gconstpointer	  node2);
sl@0
   182
static inline void		emission_push		(Emission	**emission_list_p,
sl@0
   183
							 Emission	 *emission);
sl@0
   184
static inline void		emission_pop		(Emission	**emission_list_p,
sl@0
   185
							 Emission	 *emission);
sl@0
   186
static inline Emission*		emission_find		(Emission	 *emission_list,
sl@0
   187
							 guint		  signal_id,
sl@0
   188
							 GQuark		  detail,
sl@0
   189
							 gpointer	  instance);
sl@0
   190
static gint			class_closures_cmp	(gconstpointer	  node1,
sl@0
   191
							 gconstpointer	  node2);
sl@0
   192
static gint			signal_key_cmp		(gconstpointer	  node1,
sl@0
   193
							 gconstpointer	  node2);
sl@0
   194
static	      gboolean		signal_emit_unlocked_R	(SignalNode	 *node,
sl@0
   195
							 GQuark		  detail,
sl@0
   196
							 gpointer	  instance,
sl@0
   197
							 GValue		 *return_value,
sl@0
   198
							 const GValue	 *instance_and_params);
sl@0
   199
static const gchar *            type_debug_name         (GType            type);
sl@0
   200
sl@0
   201
sl@0
   202
/* --- structures --- */
sl@0
   203
typedef struct
sl@0
   204
{
sl@0
   205
  GSignalAccumulator func;
sl@0
   206
  gpointer           data;
sl@0
   207
} SignalAccumulator;
sl@0
   208
typedef struct
sl@0
   209
{
sl@0
   210
  GHook hook;
sl@0
   211
  GQuark detail;
sl@0
   212
} SignalHook;
sl@0
   213
#define	SIGNAL_HOOK(hook)	((SignalHook*) (hook))
sl@0
   214
sl@0
   215
struct _SignalNode
sl@0
   216
{
sl@0
   217
  /* permanent portion */
sl@0
   218
  guint              signal_id;
sl@0
   219
  GType              itype;
sl@0
   220
  const gchar       *name;
sl@0
   221
  guint              destroyed : 1;
sl@0
   222
  
sl@0
   223
  /* reinitializable portion */
sl@0
   224
  guint		     test_class_offset : 12;
sl@0
   225
  guint              flags : 8;
sl@0
   226
  guint              n_params : 8;
sl@0
   227
  GType		    *param_types; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
sl@0
   228
  GType		     return_type; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
sl@0
   229
  GBSearchArray     *class_closure_bsa;
sl@0
   230
  SignalAccumulator *accumulator;
sl@0
   231
  GSignalCMarshaller c_marshaller;
sl@0
   232
  GHookList         *emission_hooks;
sl@0
   233
};
sl@0
   234
#define	MAX_TEST_CLASS_OFFSET	(4096)	/* 2^12, 12 bits for test_class_offset */
sl@0
   235
#define	TEST_CLASS_MAGIC	(1)	/* indicates NULL class closure, candidate for NOP optimization */
sl@0
   236
sl@0
   237
struct _SignalKey
sl@0
   238
{
sl@0
   239
  GType  itype;
sl@0
   240
  GQuark quark;
sl@0
   241
  guint  signal_id;
sl@0
   242
};
sl@0
   243
sl@0
   244
struct _Emission
sl@0
   245
{
sl@0
   246
  Emission             *next;
sl@0
   247
  gpointer              instance;
sl@0
   248
  GSignalInvocationHint ihint;
sl@0
   249
  EmissionState         state;
sl@0
   250
  GType			chain_type;
sl@0
   251
};
sl@0
   252
sl@0
   253
struct _HandlerList
sl@0
   254
{
sl@0
   255
  guint    signal_id;
sl@0
   256
  Handler *handlers;
sl@0
   257
  Handler *tail_before;  /* normal signal handlers are appended here  */
sl@0
   258
  Handler *tail_after;   /* CONNECT_AFTER handlers are appended here  */
sl@0
   259
};
sl@0
   260
sl@0
   261
struct _Handler
sl@0
   262
{
sl@0
   263
  gulong        sequential_number;
sl@0
   264
  Handler      *next;
sl@0
   265
  Handler      *prev;
sl@0
   266
  GQuark	detail;
sl@0
   267
  guint         ref_count;
sl@0
   268
  guint         block_count : 16;
sl@0
   269
#define HANDLER_MAX_BLOCK_COUNT (1 << 16)
sl@0
   270
  guint         after : 1;
sl@0
   271
  GClosure     *closure;
sl@0
   272
};
sl@0
   273
struct _HandlerMatch
sl@0
   274
{
sl@0
   275
  Handler      *handler;
sl@0
   276
  HandlerMatch *next;
sl@0
   277
  guint         signal_id;
sl@0
   278
};
sl@0
   279
sl@0
   280
typedef struct
sl@0
   281
{
sl@0
   282
  GType     instance_type; /* 0 for default closure */
sl@0
   283
  GClosure *closure;
sl@0
   284
} ClassClosure;
sl@0
   285
sl@0
   286
sl@0
   287
/* --- variables --- */
sl@0
   288
#if EMULATOR
sl@0
   289
sl@0
   290
PLS(g_signal_key_bsa,gsignal,GBSearchArray *)
sl@0
   291
PLS(g_signal_hlbsa_bconfig,gsignal,GBSearchConfig)
sl@0
   292
PLS(g_class_closure_bconfig,gsignal,GBSearchConfig)
sl@0
   293
PLS(g_handler_list_bsa_ht,gsignal,GHashTable    *)
sl@0
   294
PLS(g_recursive_emissions,gsignal,Emission *)
sl@0
   295
PLS(g_restart_emissions ,gsignal,Emission *)
sl@0
   296
PLS(g_handler_sequential_number ,gsignal,gulong)
sl@0
   297
PLS_MACRO(g_signal_mutex,gsignal,GStaticMutex)
sl@0
   298
PLS(g_n_signal_nodes,gsignal,guint)
sl@0
   299
PLS(g_signal_nodes ,gsignal,SignalNode   **)
sl@0
   300
sl@0
   301
#define g_signal_key_bsa (*FUNCTION_NAME(g_signal_key_bsa,gsignal)())
sl@0
   302
#define g_signal_hlbsa_bconfig (*FUNCTION_NAME(g_signal_hlbsa_bconfig,gsignal)())
sl@0
   303
#define g_class_closure_bconfig (*FUNCTION_NAME(g_class_closure_bconfig,gsignal)())
sl@0
   304
#define g_handler_list_bsa_ht (*FUNCTION_NAME(g_handler_list_bsa_ht,gsignal)())
sl@0
   305
#define g_recursive_emissions (*FUNCTION_NAME(g_recursive_emissions,gsignal)())
sl@0
   306
#define g_restart_emissions  (*FUNCTION_NAME(g_restart_emissions ,gsignal)())
sl@0
   307
#define g_handler_sequential_number  (*FUNCTION_NAME(g_handler_sequential_number ,gsignal)())
sl@0
   308
#define g__g_signal_mutex_lock (*FUNCTION_NAME_MACRO(g_signal_mutex,gsignal)())
sl@0
   309
#define g_n_signal_nodes (*FUNCTION_NAME(g_n_signal_nodes,gsignal)())
sl@0
   310
#define g_signal_nodes (*FUNCTION_NAME(g_signal_nodes,gsignal)())
sl@0
   311
sl@0
   312
const GBSearchConfig temp_g_signal_hlbsa_bconfig = {
sl@0
   313
  sizeof (HandlerList),
sl@0
   314
  handler_lists_cmp,
sl@0
   315
  0,
sl@0
   316
};
sl@0
   317
sl@0
   318
 const GBSearchConfig temp_g_class_closure_bconfig = {
sl@0
   319
  sizeof (ClassClosure),
sl@0
   320
  class_closures_cmp,
sl@0
   321
  0,
sl@0
   322
};
sl@0
   323
sl@0
   324
#else
sl@0
   325
static GBSearchArray *g_signal_key_bsa = NULL;
sl@0
   326
#endif//EMULATOR
sl@0
   327
static const GBSearchConfig g_signal_key_bconfig = {
sl@0
   328
  sizeof (SignalKey),
sl@0
   329
  signal_key_cmp,
sl@0
   330
  G_BSEARCH_ARRAY_ALIGN_POWER2,
sl@0
   331
};
sl@0
   332
#if (!EMULATOR)
sl@0
   333
static GBSearchConfig g_signal_hlbsa_bconfig = {
sl@0
   334
  sizeof (HandlerList),
sl@0
   335
  handler_lists_cmp,
sl@0
   336
  0,
sl@0
   337
};
sl@0
   338
static GBSearchConfig g_class_closure_bconfig = {
sl@0
   339
  sizeof (ClassClosure),
sl@0
   340
  class_closures_cmp,
sl@0
   341
  0,
sl@0
   342
};
sl@0
   343
static GHashTable    *g_handler_list_bsa_ht = NULL;
sl@0
   344
static Emission      *g_recursive_emissions = NULL;
sl@0
   345
static Emission      *g_restart_emissions = NULL;
sl@0
   346
static gulong         g_handler_sequential_number = 1;
sl@0
   347
G_LOCK_DEFINE_STATIC (g_signal_mutex);
sl@0
   348
#endif//EMULATOR
sl@0
   349
sl@0
   350
#define	SIGNAL_LOCK()		G_LOCK (g_signal_mutex)
sl@0
   351
#define	SIGNAL_UNLOCK()		G_UNLOCK (g_signal_mutex)
sl@0
   352
sl@0
   353
/* --- signal nodes --- */
sl@0
   354
#if (!EMULATOR)
sl@0
   355
static guint          g_n_signal_nodes = 0;
sl@0
   356
static SignalNode   **g_signal_nodes = NULL;
sl@0
   357
sl@0
   358
#endif /* EMULATOR */
sl@0
   359
sl@0
   360
static inline SignalNode*
sl@0
   361
LOOKUP_SIGNAL_NODE (register guint signal_id)
sl@0
   362
{
sl@0
   363
  if (signal_id < g_n_signal_nodes)
sl@0
   364
    return g_signal_nodes[signal_id];
sl@0
   365
  else
sl@0
   366
    return NULL;
sl@0
   367
}
sl@0
   368
sl@0
   369
sl@0
   370
/* --- functions --- */
sl@0
   371
static inline guint
sl@0
   372
signal_id_lookup (GQuark quark,
sl@0
   373
		  GType  itype)
sl@0
   374
{
sl@0
   375
  GType *ifaces, type = itype;
sl@0
   376
  SignalKey key;
sl@0
   377
  guint n_ifaces;
sl@0
   378
sl@0
   379
  key.quark = quark;
sl@0
   380
sl@0
   381
  /* try looking up signals for this type and its ancestors */
sl@0
   382
  do
sl@0
   383
    {
sl@0
   384
      SignalKey *signal_key;
sl@0
   385
      
sl@0
   386
      key.itype = type;
sl@0
   387
      signal_key = g_bsearch_array_lookup (g_signal_key_bsa, &g_signal_key_bconfig, &key);
sl@0
   388
      
sl@0
   389
      if (signal_key)
sl@0
   390
	return signal_key->signal_id;
sl@0
   391
      
sl@0
   392
      type = g_type_parent (type);
sl@0
   393
    }
sl@0
   394
  while (type);
sl@0
   395
sl@0
   396
  /* no luck, try interfaces it exports */
sl@0
   397
  ifaces = g_type_interfaces (itype, &n_ifaces);
sl@0
   398
  while (n_ifaces--)
sl@0
   399
    {
sl@0
   400
      SignalKey *signal_key;
sl@0
   401
sl@0
   402
      key.itype = ifaces[n_ifaces];
sl@0
   403
      signal_key = g_bsearch_array_lookup (g_signal_key_bsa, &g_signal_key_bconfig, &key);
sl@0
   404
sl@0
   405
      if (signal_key)
sl@0
   406
	{
sl@0
   407
	  g_free (ifaces);
sl@0
   408
	  return signal_key->signal_id;
sl@0
   409
	}
sl@0
   410
    }
sl@0
   411
  g_free (ifaces);
sl@0
   412
  
sl@0
   413
  return 0;
sl@0
   414
}
sl@0
   415
sl@0
   416
static gint
sl@0
   417
class_closures_cmp (gconstpointer node1,
sl@0
   418
		    gconstpointer node2)
sl@0
   419
{
sl@0
   420
  const ClassClosure *c1 = node1, *c2 = node2;
sl@0
   421
  
sl@0
   422
  return G_BSEARCH_ARRAY_CMP (c1->instance_type, c2->instance_type);
sl@0
   423
}
sl@0
   424
sl@0
   425
static gint
sl@0
   426
handler_lists_cmp (gconstpointer node1,
sl@0
   427
                   gconstpointer node2)
sl@0
   428
{
sl@0
   429
  const HandlerList *hlist1 = node1, *hlist2 = node2;
sl@0
   430
  
sl@0
   431
  return G_BSEARCH_ARRAY_CMP (hlist1->signal_id, hlist2->signal_id);
sl@0
   432
}
sl@0
   433
sl@0
   434
static inline HandlerList*
sl@0
   435
handler_list_ensure (guint    signal_id,
sl@0
   436
		     gpointer instance)
sl@0
   437
{
sl@0
   438
  GBSearchArray *hlbsa = g_hash_table_lookup (g_handler_list_bsa_ht, instance);
sl@0
   439
  HandlerList key;
sl@0
   440
  
sl@0
   441
  key.signal_id = signal_id;
sl@0
   442
  key.handlers    = NULL;
sl@0
   443
  key.tail_before = NULL;
sl@0
   444
  key.tail_after  = NULL;
sl@0
   445
  if (!hlbsa)
sl@0
   446
    {
sl@0
   447
      hlbsa = g_bsearch_array_create (&g_signal_hlbsa_bconfig);
sl@0
   448
      hlbsa = g_bsearch_array_insert (hlbsa, &g_signal_hlbsa_bconfig, &key);
sl@0
   449
      g_hash_table_insert (g_handler_list_bsa_ht, instance, hlbsa);
sl@0
   450
    }
sl@0
   451
  else
sl@0
   452
    {
sl@0
   453
      GBSearchArray *o = hlbsa;
sl@0
   454
sl@0
   455
      hlbsa = g_bsearch_array_insert (o, &g_signal_hlbsa_bconfig, &key);
sl@0
   456
      if (hlbsa != o)
sl@0
   457
	g_hash_table_insert (g_handler_list_bsa_ht, instance, hlbsa);
sl@0
   458
    }
sl@0
   459
  return g_bsearch_array_lookup (hlbsa, &g_signal_hlbsa_bconfig, &key);
sl@0
   460
}
sl@0
   461
sl@0
   462
static inline HandlerList*
sl@0
   463
handler_list_lookup (guint    signal_id,
sl@0
   464
		     gpointer instance)
sl@0
   465
{
sl@0
   466
  GBSearchArray *hlbsa = g_hash_table_lookup (g_handler_list_bsa_ht, instance);
sl@0
   467
  HandlerList key;
sl@0
   468
  
sl@0
   469
  key.signal_id = signal_id;
sl@0
   470
  
sl@0
   471
  return hlbsa ? g_bsearch_array_lookup (hlbsa, &g_signal_hlbsa_bconfig, &key) : NULL;
sl@0
   472
}
sl@0
   473
sl@0
   474
static Handler*
sl@0
   475
handler_lookup (gpointer instance,
sl@0
   476
		gulong   handler_id,
sl@0
   477
		guint   *signal_id_p)
sl@0
   478
{
sl@0
   479
  GBSearchArray *hlbsa = g_hash_table_lookup (g_handler_list_bsa_ht, instance);
sl@0
   480
  
sl@0
   481
  if (hlbsa)
sl@0
   482
    {
sl@0
   483
      guint i;
sl@0
   484
      
sl@0
   485
      for (i = 0; i < hlbsa->n_nodes; i++)
sl@0
   486
        {
sl@0
   487
          HandlerList *hlist = g_bsearch_array_get_nth (hlbsa, &g_signal_hlbsa_bconfig, i);
sl@0
   488
          Handler *handler;
sl@0
   489
          
sl@0
   490
          for (handler = hlist->handlers; handler; handler = handler->next)
sl@0
   491
            if (handler->sequential_number == handler_id)
sl@0
   492
              {
sl@0
   493
                if (signal_id_p)
sl@0
   494
                  *signal_id_p = hlist->signal_id;
sl@0
   495
		
sl@0
   496
                return handler;
sl@0
   497
              }
sl@0
   498
        }
sl@0
   499
    }
sl@0
   500
  
sl@0
   501
  return NULL;
sl@0
   502
}
sl@0
   503
sl@0
   504
static inline HandlerMatch*
sl@0
   505
handler_match_prepend (HandlerMatch *list,
sl@0
   506
		       Handler      *handler,
sl@0
   507
		       guint	     signal_id)
sl@0
   508
{
sl@0
   509
  HandlerMatch *node;
sl@0
   510
  
sl@0
   511
  node = g_slice_new (HandlerMatch);
sl@0
   512
  node->handler = handler;
sl@0
   513
  node->next = list;
sl@0
   514
  node->signal_id = signal_id;
sl@0
   515
  handler_ref (handler);
sl@0
   516
  
sl@0
   517
  return node;
sl@0
   518
}
sl@0
   519
static inline HandlerMatch*
sl@0
   520
handler_match_free1_R (HandlerMatch *node,
sl@0
   521
		       gpointer      instance)
sl@0
   522
{
sl@0
   523
  HandlerMatch *next = node->next;
sl@0
   524
  
sl@0
   525
  handler_unref_R (node->signal_id, instance, node->handler);
sl@0
   526
  g_slice_free (HandlerMatch, node);
sl@0
   527
  
sl@0
   528
  return next;
sl@0
   529
}
sl@0
   530
sl@0
   531
static HandlerMatch*
sl@0
   532
handlers_find (gpointer         instance,
sl@0
   533
	       GSignalMatchType mask,
sl@0
   534
	       guint            signal_id,
sl@0
   535
	       GQuark           detail,
sl@0
   536
	       GClosure        *closure,
sl@0
   537
	       gpointer         func,
sl@0
   538
	       gpointer         data,
sl@0
   539
	       gboolean         one_and_only)
sl@0
   540
{
sl@0
   541
  HandlerMatch *mlist = NULL;
sl@0
   542
  
sl@0
   543
  if (mask & G_SIGNAL_MATCH_ID)
sl@0
   544
    {
sl@0
   545
      HandlerList *hlist = handler_list_lookup (signal_id, instance);
sl@0
   546
      Handler *handler;
sl@0
   547
      SignalNode *node = NULL;
sl@0
   548
      
sl@0
   549
      if (mask & G_SIGNAL_MATCH_FUNC)
sl@0
   550
	{
sl@0
   551
	  node = LOOKUP_SIGNAL_NODE (signal_id);
sl@0
   552
	  if (!node || !node->c_marshaller)
sl@0
   553
	    return NULL;
sl@0
   554
	}
sl@0
   555
      
sl@0
   556
      mask = ~mask;
sl@0
   557
      for (handler = hlist ? hlist->handlers : NULL; handler; handler = handler->next)
sl@0
   558
        if (handler->sequential_number &&
sl@0
   559
	    ((mask & G_SIGNAL_MATCH_DETAIL) || handler->detail == detail) &&
sl@0
   560
	    ((mask & G_SIGNAL_MATCH_CLOSURE) || handler->closure == closure) &&
sl@0
   561
            ((mask & G_SIGNAL_MATCH_DATA) || handler->closure->data == data) &&
sl@0
   562
	    ((mask & G_SIGNAL_MATCH_UNBLOCKED) || handler->block_count == 0) &&
sl@0
   563
	    ((mask & G_SIGNAL_MATCH_FUNC) || (handler->closure->marshal == node->c_marshaller &&
sl@0
   564
					      handler->closure->meta_marshal == 0 &&
sl@0
   565
					      ((GCClosure*) handler->closure)->callback == func)))
sl@0
   566
	  {
sl@0
   567
	    mlist = handler_match_prepend (mlist, handler, signal_id);
sl@0
   568
	    if (one_and_only)
sl@0
   569
	      return mlist;
sl@0
   570
	  }
sl@0
   571
    }
sl@0
   572
  else
sl@0
   573
    {
sl@0
   574
      GBSearchArray *hlbsa = g_hash_table_lookup (g_handler_list_bsa_ht, instance);
sl@0
   575
      
sl@0
   576
      mask = ~mask;
sl@0
   577
      if (hlbsa)
sl@0
   578
        {
sl@0
   579
          guint i;
sl@0
   580
          
sl@0
   581
          for (i = 0; i < hlbsa->n_nodes; i++)
sl@0
   582
            {
sl@0
   583
              HandlerList *hlist = g_bsearch_array_get_nth (hlbsa, &g_signal_hlbsa_bconfig, i);
sl@0
   584
	      SignalNode *node = NULL;
sl@0
   585
              Handler *handler;
sl@0
   586
              
sl@0
   587
	      if (!(mask & G_SIGNAL_MATCH_FUNC))
sl@0
   588
		{
sl@0
   589
		  node = LOOKUP_SIGNAL_NODE (hlist->signal_id);
sl@0
   590
		  if (!node->c_marshaller)
sl@0
   591
		    continue;
sl@0
   592
		}
sl@0
   593
	      
sl@0
   594
              for (handler = hlist->handlers; handler; handler = handler->next)
sl@0
   595
		if (handler->sequential_number &&
sl@0
   596
		    ((mask & G_SIGNAL_MATCH_DETAIL) || handler->detail == detail) &&
sl@0
   597
                    ((mask & G_SIGNAL_MATCH_CLOSURE) || handler->closure == closure) &&
sl@0
   598
                    ((mask & G_SIGNAL_MATCH_DATA) || handler->closure->data == data) &&
sl@0
   599
		    ((mask & G_SIGNAL_MATCH_UNBLOCKED) || handler->block_count == 0) &&
sl@0
   600
		    ((mask & G_SIGNAL_MATCH_FUNC) || (handler->closure->marshal == node->c_marshaller &&
sl@0
   601
						      handler->closure->meta_marshal == 0 &&
sl@0
   602
						      ((GCClosure*) handler->closure)->callback == func)))
sl@0
   603
		  {
sl@0
   604
		    mlist = handler_match_prepend (mlist, handler, hlist->signal_id);
sl@0
   605
		    if (one_and_only)
sl@0
   606
		      return mlist;
sl@0
   607
		  }
sl@0
   608
            }
sl@0
   609
        }
sl@0
   610
    }
sl@0
   611
  
sl@0
   612
  return mlist;
sl@0
   613
}
sl@0
   614
sl@0
   615
static inline Handler*
sl@0
   616
handler_new (gboolean after)
sl@0
   617
{
sl@0
   618
  Handler *handler = g_slice_new (Handler);
sl@0
   619
#ifndef G_DISABLE_CHECKS
sl@0
   620
  if (g_handler_sequential_number < 1)
sl@0
   621
    g_error (G_STRLOC ": handler id overflow, %s", REPORT_BUG);
sl@0
   622
#endif
sl@0
   623
  
sl@0
   624
  handler->sequential_number = g_handler_sequential_number++;
sl@0
   625
  handler->prev = NULL;
sl@0
   626
  handler->next = NULL;
sl@0
   627
  handler->detail = 0;
sl@0
   628
  handler->ref_count = 1;
sl@0
   629
  handler->block_count = 0;
sl@0
   630
  handler->after = after != FALSE;
sl@0
   631
  handler->closure = NULL;
sl@0
   632
  
sl@0
   633
  return handler;
sl@0
   634
}
sl@0
   635
sl@0
   636
static inline void
sl@0
   637
handler_ref (Handler *handler)
sl@0
   638
{
sl@0
   639
  g_return_if_fail (handler->ref_count > 0);
sl@0
   640
  
sl@0
   641
  g_atomic_int_inc ((int *)&handler->ref_count);
sl@0
   642
}
sl@0
   643
sl@0
   644
static inline void
sl@0
   645
handler_unref_R (guint    signal_id,
sl@0
   646
		 gpointer instance,
sl@0
   647
		 Handler *handler)
sl@0
   648
{
sl@0
   649
  gboolean is_zero;
sl@0
   650
sl@0
   651
  g_return_if_fail (handler->ref_count > 0);
sl@0
   652
  
sl@0
   653
  is_zero = g_atomic_int_dec_and_test ((int *)&handler->ref_count);
sl@0
   654
sl@0
   655
  if (G_UNLIKELY (is_zero))
sl@0
   656
    {
sl@0
   657
      HandlerList *hlist = NULL;
sl@0
   658
sl@0
   659
      if (handler->next)
sl@0
   660
        handler->next->prev = handler->prev;
sl@0
   661
      if (handler->prev)    /* watch out for g_signal_handlers_destroy()! */
sl@0
   662
        handler->prev->next = handler->next;
sl@0
   663
      else
sl@0
   664
        {
sl@0
   665
          hlist = handler_list_lookup (signal_id, instance);
sl@0
   666
          hlist->handlers = handler->next;
sl@0
   667
        }
sl@0
   668
sl@0
   669
      if (instance)
sl@0
   670
        {
sl@0
   671
          /*  check if we are removing the handler pointed to by tail_before  */
sl@0
   672
          if (!handler->after && (!handler->next || handler->next->after))
sl@0
   673
            {
sl@0
   674
              if (!hlist)
sl@0
   675
                hlist = handler_list_lookup (signal_id, instance);
sl@0
   676
              if (hlist)
sl@0
   677
                {
sl@0
   678
                  g_assert (hlist->tail_before == handler); /* paranoid */
sl@0
   679
                  hlist->tail_before = handler->prev;
sl@0
   680
                }
sl@0
   681
            }
sl@0
   682
sl@0
   683
          /*  check if we are removing the handler pointed to by tail_after  */
sl@0
   684
          if (!handler->next)
sl@0
   685
            {
sl@0
   686
              if (!hlist)
sl@0
   687
                hlist = handler_list_lookup (signal_id, instance);
sl@0
   688
              if (hlist)
sl@0
   689
                {
sl@0
   690
                  g_assert (hlist->tail_after == handler); /* paranoid */
sl@0
   691
                  hlist->tail_after = handler->prev;
sl@0
   692
                }
sl@0
   693
            }
sl@0
   694
        }
sl@0
   695
sl@0
   696
      SIGNAL_UNLOCK ();
sl@0
   697
      g_closure_unref (handler->closure);
sl@0
   698
      SIGNAL_LOCK ();
sl@0
   699
      g_slice_free (Handler, handler);
sl@0
   700
    }
sl@0
   701
}
sl@0
   702
sl@0
   703
static void
sl@0
   704
handler_insert (guint    signal_id,
sl@0
   705
		gpointer instance,
sl@0
   706
		Handler  *handler)
sl@0
   707
{
sl@0
   708
  HandlerList *hlist;
sl@0
   709
  
sl@0
   710
  g_assert (handler->prev == NULL && handler->next == NULL); /* paranoid */
sl@0
   711
  
sl@0
   712
  hlist = handler_list_ensure (signal_id, instance);
sl@0
   713
  if (!hlist->handlers)
sl@0
   714
    {
sl@0
   715
      hlist->handlers = handler;
sl@0
   716
      if (!handler->after)
sl@0
   717
        hlist->tail_before = handler;
sl@0
   718
    }
sl@0
   719
  else if (handler->after)
sl@0
   720
    {
sl@0
   721
      handler->prev = hlist->tail_after;
sl@0
   722
      hlist->tail_after->next = handler;
sl@0
   723
    }
sl@0
   724
  else
sl@0
   725
    {
sl@0
   726
      if (hlist->tail_before)
sl@0
   727
        {
sl@0
   728
          handler->next = hlist->tail_before->next;
sl@0
   729
          if (handler->next)
sl@0
   730
            handler->next->prev = handler;
sl@0
   731
          handler->prev = hlist->tail_before;
sl@0
   732
          hlist->tail_before->next = handler;
sl@0
   733
        }
sl@0
   734
      else /* insert !after handler into a list of only after handlers */
sl@0
   735
        {
sl@0
   736
          handler->next = hlist->handlers;
sl@0
   737
          if (handler->next)
sl@0
   738
            handler->next->prev = handler;
sl@0
   739
          hlist->handlers = handler;
sl@0
   740
        }
sl@0
   741
      hlist->tail_before = handler;
sl@0
   742
    }
sl@0
   743
sl@0
   744
  if (!handler->next)
sl@0
   745
    hlist->tail_after = handler;
sl@0
   746
}
sl@0
   747
sl@0
   748
static inline void
sl@0
   749
emission_push (Emission **emission_list_p,
sl@0
   750
	       Emission  *emission)
sl@0
   751
{
sl@0
   752
  emission->next = *emission_list_p;
sl@0
   753
  *emission_list_p = emission;
sl@0
   754
}
sl@0
   755
sl@0
   756
static inline void
sl@0
   757
emission_pop (Emission **emission_list_p,
sl@0
   758
	      Emission  *emission)
sl@0
   759
{
sl@0
   760
  Emission *node, *last = NULL;
sl@0
   761
sl@0
   762
  for (node = *emission_list_p; node; last = node, node = last->next)
sl@0
   763
    if (node == emission)
sl@0
   764
      {
sl@0
   765
	if (last)
sl@0
   766
	  last->next = node->next;
sl@0
   767
	else
sl@0
   768
	  *emission_list_p = node->next;
sl@0
   769
	return;
sl@0
   770
      }
sl@0
   771
  g_assert_not_reached ();
sl@0
   772
}
sl@0
   773
sl@0
   774
static inline Emission*
sl@0
   775
emission_find (Emission *emission_list,
sl@0
   776
	       guint     signal_id,
sl@0
   777
	       GQuark    detail,
sl@0
   778
	       gpointer  instance)
sl@0
   779
{
sl@0
   780
  Emission *emission;
sl@0
   781
  
sl@0
   782
  for (emission = emission_list; emission; emission = emission->next)
sl@0
   783
    if (emission->instance == instance &&
sl@0
   784
	emission->ihint.signal_id == signal_id &&
sl@0
   785
	emission->ihint.detail == detail)
sl@0
   786
      return emission;
sl@0
   787
  return NULL;
sl@0
   788
}
sl@0
   789
sl@0
   790
static inline Emission*
sl@0
   791
emission_find_innermost (gpointer instance)
sl@0
   792
{
sl@0
   793
  Emission *emission, *s = NULL, *c = NULL;
sl@0
   794
  
sl@0
   795
  for (emission = g_restart_emissions; emission; emission = emission->next)
sl@0
   796
    if (emission->instance == instance)
sl@0
   797
      {
sl@0
   798
	s = emission;
sl@0
   799
	break;
sl@0
   800
      }
sl@0
   801
  for (emission = g_recursive_emissions; emission; emission = emission->next)
sl@0
   802
    if (emission->instance == instance)
sl@0
   803
      {
sl@0
   804
	c = emission;
sl@0
   805
	break;
sl@0
   806
      }
sl@0
   807
  if (!s)
sl@0
   808
    return c;
sl@0
   809
  else if (!c)
sl@0
   810
    return s;
sl@0
   811
  else
sl@0
   812
    return G_HAVE_GROWING_STACK ? MAX (c, s) : MIN (c, s);
sl@0
   813
}
sl@0
   814
sl@0
   815
static gint
sl@0
   816
signal_key_cmp (gconstpointer node1,
sl@0
   817
                gconstpointer node2)
sl@0
   818
{
sl@0
   819
  const SignalKey *key1 = node1, *key2 = node2;
sl@0
   820
  
sl@0
   821
  if (key1->itype == key2->itype)
sl@0
   822
    return G_BSEARCH_ARRAY_CMP (key1->quark, key2->quark);
sl@0
   823
  else
sl@0
   824
    return G_BSEARCH_ARRAY_CMP (key1->itype, key2->itype);
sl@0
   825
}
sl@0
   826
sl@0
   827
void
sl@0
   828
g_signal_init (void)
sl@0
   829
{
sl@0
   830
  SIGNAL_LOCK ();
sl@0
   831
  if (!g_n_signal_nodes)
sl@0
   832
    {
sl@0
   833
      /* setup handler list binary searchable array hash table (in german, that'd be one word ;) */
sl@0
   834
      g_handler_list_bsa_ht = g_hash_table_new (g_direct_hash, NULL);
sl@0
   835
      g_signal_key_bsa = g_bsearch_array_create (&g_signal_key_bconfig);
sl@0
   836
      
sl@0
   837
      /* invalid (0) signal_id */
sl@0
   838
      g_n_signal_nodes = 1;
sl@0
   839
      g_signal_nodes = g_renew (SignalNode*, g_signal_nodes, g_n_signal_nodes);
sl@0
   840
      g_signal_nodes[0] = NULL;
sl@0
   841
    }
sl@0
   842
  SIGNAL_UNLOCK ();
sl@0
   843
}
sl@0
   844
sl@0
   845
void
sl@0
   846
_g_signals_destroy (GType itype)
sl@0
   847
{
sl@0
   848
  guint i;
sl@0
   849
  
sl@0
   850
  SIGNAL_LOCK ();
sl@0
   851
  for (i = 1; i < g_n_signal_nodes; i++)
sl@0
   852
    {
sl@0
   853
      SignalNode *node = g_signal_nodes[i];
sl@0
   854
      
sl@0
   855
      if (node->itype == itype)
sl@0
   856
        {
sl@0
   857
          if (node->destroyed)
sl@0
   858
            g_warning (G_STRLOC ": signal \"%s\" of type `%s' already destroyed",
sl@0
   859
                       node->name,
sl@0
   860
                       type_debug_name (node->itype));
sl@0
   861
          else
sl@0
   862
	    signal_destroy_R (node);
sl@0
   863
        }
sl@0
   864
    }
sl@0
   865
  SIGNAL_UNLOCK ();
sl@0
   866
}
sl@0
   867
sl@0
   868
/**
sl@0
   869
 * g_signal_stop_emission:
sl@0
   870
 * @instance: the object whose signal handlers you wish to stop.
sl@0
   871
 * @signal_id: the signal identifier, as returned by g_signal_lookup().
sl@0
   872
 * @detail: the detail which the signal was emitted with.
sl@0
   873
 *
sl@0
   874
 * Stops a signal's current emission.
sl@0
   875
 *
sl@0
   876
 * This will prevent the default method from running, if the signal was
sl@0
   877
 * %G_SIGNAL_RUN_LAST and you connected normally (i.e. without the "after"
sl@0
   878
 * flag).
sl@0
   879
 *
sl@0
   880
 * Prints a warning if used on a signal which isn't being emitted.
sl@0
   881
 */
sl@0
   882
EXPORT_C void
sl@0
   883
g_signal_stop_emission (gpointer instance,
sl@0
   884
                        guint    signal_id,
sl@0
   885
			GQuark   detail)
sl@0
   886
{
sl@0
   887
  SignalNode *node;
sl@0
   888
  
sl@0
   889
  g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
sl@0
   890
  g_return_if_fail (signal_id > 0);
sl@0
   891
  
sl@0
   892
  SIGNAL_LOCK ();
sl@0
   893
  node = LOOKUP_SIGNAL_NODE (signal_id);
sl@0
   894
  if (node && detail && !(node->flags & G_SIGNAL_DETAILED))
sl@0
   895
    {
sl@0
   896
      g_warning ("%s: signal id `%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
sl@0
   897
      SIGNAL_UNLOCK ();
sl@0
   898
      return;
sl@0
   899
    }
sl@0
   900
  if (node && g_type_is_a (G_TYPE_FROM_INSTANCE (instance), node->itype))
sl@0
   901
    {
sl@0
   902
      Emission *emission_list = node->flags & G_SIGNAL_NO_RECURSE ? g_restart_emissions : g_recursive_emissions;
sl@0
   903
      Emission *emission = emission_find (emission_list, signal_id, detail, instance);
sl@0
   904
      
sl@0
   905
      if (emission)
sl@0
   906
        {
sl@0
   907
          if (emission->state == EMISSION_HOOK)
sl@0
   908
            g_warning (G_STRLOC ": emission of signal \"%s\" for instance `%p' cannot be stopped from emission hook",
sl@0
   909
                       node->name, instance);
sl@0
   910
          else if (emission->state == EMISSION_RUN)
sl@0
   911
            emission->state = EMISSION_STOP;
sl@0
   912
        }
sl@0
   913
      else
sl@0
   914
        g_warning (G_STRLOC ": no emission of signal \"%s\" to stop for instance `%p'",
sl@0
   915
                   node->name, instance);
sl@0
   916
    }
sl@0
   917
  else
sl@0
   918
    g_warning ("%s: signal id `%u' is invalid for instance `%p'", G_STRLOC, signal_id, instance);
sl@0
   919
  SIGNAL_UNLOCK ();
sl@0
   920
}
sl@0
   921
sl@0
   922
static void
sl@0
   923
signal_finalize_hook (GHookList *hook_list,
sl@0
   924
		      GHook     *hook)
sl@0
   925
{
sl@0
   926
  GDestroyNotify destroy = hook->destroy;
sl@0
   927
sl@0
   928
  if (destroy)
sl@0
   929
    {
sl@0
   930
      hook->destroy = NULL;
sl@0
   931
      SIGNAL_UNLOCK ();
sl@0
   932
      destroy (hook->data);
sl@0
   933
      SIGNAL_LOCK ();
sl@0
   934
    }
sl@0
   935
}
sl@0
   936
sl@0
   937
#if EMULATOR
sl@0
   938
PLS(seq_hook_id ,g_signal_add_emission_hook ,gulong)
sl@0
   939
#define seq_hook_id  (*FUNCTION_NAME(seq_hook_id ,g_signal_add_emission_hook)())
sl@0
   940
#endif /* EMULATOR */
sl@0
   941
sl@0
   942
/**
sl@0
   943
 * g_signal_add_emission_hook:
sl@0
   944
 * @signal_id: the signal identifier, as returned by g_signal_lookup().
sl@0
   945
 * @detail: the detail on which to call the hook.
sl@0
   946
 * @hook_func: a #GSignalEmissionHook function.
sl@0
   947
 * @hook_data: user data for @hook_func.
sl@0
   948
 * @data_destroy: a #GDestroyNotify for @hook_data.
sl@0
   949
 *
sl@0
   950
 * Adds an emission hook for a signal, which will get called for any emission
sl@0
   951
 * of that signal, independent of the instance. This is possible only
sl@0
   952
 * for signals which don't have #G_SIGNAL_NO_HOOKS flag set.
sl@0
   953
 *
sl@0
   954
 * Returns: the hook id, for later use with g_signal_remove_emission_hook().
sl@0
   955
 */
sl@0
   956
EXPORT_C gulong
sl@0
   957
g_signal_add_emission_hook (guint               signal_id,
sl@0
   958
			    GQuark              detail,
sl@0
   959
			    GSignalEmissionHook hook_func,
sl@0
   960
			    gpointer            hook_data,
sl@0
   961
			    GDestroyNotify      data_destroy)
sl@0
   962
{
sl@0
   963
  #if !(EMULATOR)
sl@0
   964
  static gulong seq_hook_id = 1;
sl@0
   965
  #endif /* EMULATOR */
sl@0
   966
  SignalNode *node;
sl@0
   967
  GHook *hook;
sl@0
   968
  SignalHook *signal_hook;
sl@0
   969
sl@0
   970
  g_return_val_if_fail (signal_id > 0, 0);
sl@0
   971
  g_return_val_if_fail (hook_func != NULL, 0);
sl@0
   972
sl@0
   973
  SIGNAL_LOCK ();
sl@0
   974
  node = LOOKUP_SIGNAL_NODE (signal_id);
sl@0
   975
  if (!node || node->destroyed)
sl@0
   976
    {
sl@0
   977
      g_warning ("%s: invalid signal id `%u'", G_STRLOC, signal_id);
sl@0
   978
      SIGNAL_UNLOCK ();
sl@0
   979
      return 0;
sl@0
   980
    }
sl@0
   981
  if (node->flags & G_SIGNAL_NO_HOOKS) 
sl@0
   982
    {
sl@0
   983
      g_warning ("%s: signal id `%u' does not support emission hooks (G_SIGNAL_NO_HOOKS flag set)", G_STRLOC, signal_id);
sl@0
   984
      SIGNAL_UNLOCK ();
sl@0
   985
      return 0;
sl@0
   986
    }
sl@0
   987
  if (detail && !(node->flags & G_SIGNAL_DETAILED))
sl@0
   988
    {
sl@0
   989
      g_warning ("%s: signal id `%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
sl@0
   990
      SIGNAL_UNLOCK ();
sl@0
   991
      return 0;
sl@0
   992
    }
sl@0
   993
  if (!node->emission_hooks)
sl@0
   994
    {
sl@0
   995
      node->emission_hooks = g_new (GHookList, 1);
sl@0
   996
      g_hook_list_init (node->emission_hooks, sizeof (SignalHook));
sl@0
   997
      node->emission_hooks->finalize_hook = signal_finalize_hook;
sl@0
   998
    }
sl@0
   999
  hook = g_hook_alloc (node->emission_hooks);
sl@0
  1000
  hook->data = hook_data;
sl@0
  1001
  hook->func = (gpointer) hook_func;
sl@0
  1002
  hook->destroy = data_destroy;
sl@0
  1003
  signal_hook = SIGNAL_HOOK (hook);
sl@0
  1004
  signal_hook->detail = detail;
sl@0
  1005
  node->emission_hooks->seq_id = seq_hook_id;
sl@0
  1006
  g_hook_append (node->emission_hooks, hook);
sl@0
  1007
  seq_hook_id = node->emission_hooks->seq_id;
sl@0
  1008
  SIGNAL_UNLOCK ();
sl@0
  1009
sl@0
  1010
  return hook->hook_id;
sl@0
  1011
}
sl@0
  1012
sl@0
  1013
#if EMULATOR
sl@0
  1014
#undef seq_hook_id 
sl@0
  1015
#endif /* EMULATOR */
sl@0
  1016
sl@0
  1017
/**
sl@0
  1018
 * g_signal_remove_emission_hook:
sl@0
  1019
 * @signal_id: the id of the signal
sl@0
  1020
 * @hook_id: the id of the emission hook, as returned by
sl@0
  1021
 *  g_signal_add_emission_hook()
sl@0
  1022
 *
sl@0
  1023
 * Deletes an emission hook.
sl@0
  1024
 */
sl@0
  1025
EXPORT_C void
sl@0
  1026
g_signal_remove_emission_hook (guint  signal_id,
sl@0
  1027
			       gulong hook_id)
sl@0
  1028
{
sl@0
  1029
  SignalNode *node;
sl@0
  1030
sl@0
  1031
  g_return_if_fail (signal_id > 0);
sl@0
  1032
  g_return_if_fail (hook_id > 0);
sl@0
  1033
sl@0
  1034
  SIGNAL_LOCK ();
sl@0
  1035
  node = LOOKUP_SIGNAL_NODE (signal_id);
sl@0
  1036
  if (!node || node->destroyed)
sl@0
  1037
    g_warning ("%s: invalid signal id `%u'", G_STRLOC, signal_id);
sl@0
  1038
  else if (!node->emission_hooks || !g_hook_destroy (node->emission_hooks, hook_id))
sl@0
  1039
    g_warning ("%s: signal \"%s\" had no hook (%lu) to remove", G_STRLOC, node->name, hook_id);
sl@0
  1040
  SIGNAL_UNLOCK ();
sl@0
  1041
}
sl@0
  1042
sl@0
  1043
static inline guint
sl@0
  1044
signal_parse_name (const gchar *name,
sl@0
  1045
		   GType        itype,
sl@0
  1046
		   GQuark      *detail_p,
sl@0
  1047
		   gboolean     force_quark)
sl@0
  1048
{
sl@0
  1049
  const gchar *colon = strchr (name, ':');
sl@0
  1050
  guint signal_id;
sl@0
  1051
  
sl@0
  1052
  if (!colon)
sl@0
  1053
    {
sl@0
  1054
      signal_id = signal_id_lookup (g_quark_try_string (name), itype);
sl@0
  1055
      if (signal_id && detail_p)
sl@0
  1056
	*detail_p = 0;
sl@0
  1057
    }
sl@0
  1058
  else if (colon[1] == ':')
sl@0
  1059
    {
sl@0
  1060
      gchar buffer[32];
sl@0
  1061
      guint l = colon - name;
sl@0
  1062
      
sl@0
  1063
      if (l < 32)
sl@0
  1064
	{
sl@0
  1065
	  memcpy (buffer, name, l);
sl@0
  1066
	  buffer[l] = 0;
sl@0
  1067
	  signal_id = signal_id_lookup (g_quark_try_string (buffer), itype);
sl@0
  1068
	}
sl@0
  1069
      else
sl@0
  1070
	{
sl@0
  1071
	  gchar *signal = g_new (gchar, l + 1);
sl@0
  1072
	  
sl@0
  1073
	  memcpy (signal, name, l);
sl@0
  1074
	  signal[l] = 0;
sl@0
  1075
	  signal_id = signal_id_lookup (g_quark_try_string (signal), itype);
sl@0
  1076
	  g_free (signal);
sl@0
  1077
	}
sl@0
  1078
      
sl@0
  1079
      if (signal_id && detail_p)
sl@0
  1080
	*detail_p = colon[2] ? (force_quark ? g_quark_from_string : g_quark_try_string) (colon + 2) : 0;
sl@0
  1081
    }
sl@0
  1082
  else
sl@0
  1083
    signal_id = 0;
sl@0
  1084
  return signal_id;
sl@0
  1085
}
sl@0
  1086
sl@0
  1087
/**
sl@0
  1088
 * g_signal_parse_name:
sl@0
  1089
 * @detailed_signal: a string of the form "signal-name::detail".
sl@0
  1090
 * @itype: The interface/instance type that introduced "signal-name".
sl@0
  1091
 * @signal_id_p: Location to store the signal id.
sl@0
  1092
 * @detail_p: Location to store the detail quark.
sl@0
  1093
 * @force_detail_quark: %TRUE forces creation of a #GQuark for the detail.
sl@0
  1094
 *
sl@0
  1095
 * Internal function to parse a signal name into its @signal_id
sl@0
  1096
 * and @detail quark.
sl@0
  1097
 *
sl@0
  1098
 * Returns: Whether the signal name could successfully be parsed and @signal_id_p and @detail_p contain valid return values.
sl@0
  1099
 */
sl@0
  1100
EXPORT_C gboolean
sl@0
  1101
g_signal_parse_name (const gchar *detailed_signal,
sl@0
  1102
		     GType        itype,
sl@0
  1103
		     guint       *signal_id_p,
sl@0
  1104
		     GQuark      *detail_p,
sl@0
  1105
		     gboolean	  force_detail_quark)
sl@0
  1106
{
sl@0
  1107
  SignalNode *node;
sl@0
  1108
  GQuark detail = 0;
sl@0
  1109
  guint signal_id;
sl@0
  1110
  
sl@0
  1111
  g_return_val_if_fail (detailed_signal != NULL, FALSE);
sl@0
  1112
  g_return_val_if_fail (G_TYPE_IS_INSTANTIATABLE (itype) || G_TYPE_IS_INTERFACE (itype), FALSE);
sl@0
  1113
  
sl@0
  1114
  SIGNAL_LOCK ();
sl@0
  1115
  signal_id = signal_parse_name (detailed_signal, itype, &detail, force_detail_quark);
sl@0
  1116
  SIGNAL_UNLOCK ();
sl@0
  1117
sl@0
  1118
  node = signal_id ? LOOKUP_SIGNAL_NODE (signal_id) : NULL;
sl@0
  1119
  if (!node || node->destroyed ||
sl@0
  1120
      (detail && !(node->flags & G_SIGNAL_DETAILED)))
sl@0
  1121
    return FALSE;
sl@0
  1122
sl@0
  1123
  if (signal_id_p)
sl@0
  1124
    *signal_id_p = signal_id;
sl@0
  1125
  if (detail_p)
sl@0
  1126
    *detail_p = detail;
sl@0
  1127
  
sl@0
  1128
  return TRUE;
sl@0
  1129
}
sl@0
  1130
sl@0
  1131
/**
sl@0
  1132
 * g_signal_stop_emission_by_name:
sl@0
  1133
 * @instance: the object whose signal handlers you wish to stop.
sl@0
  1134
 * @detailed_signal: a string of the form "signal-name::detail".
sl@0
  1135
 *
sl@0
  1136
 * Stops a signal's current emission.
sl@0
  1137
 *
sl@0
  1138
 * This is just like g_signal_stop_emission() except it will look up the
sl@0
  1139
 * signal id for you.
sl@0
  1140
 */
sl@0
  1141
EXPORT_C void
sl@0
  1142
g_signal_stop_emission_by_name (gpointer     instance,
sl@0
  1143
				const gchar *detailed_signal)
sl@0
  1144
{
sl@0
  1145
  guint signal_id;
sl@0
  1146
  GQuark detail = 0;
sl@0
  1147
  GType itype;
sl@0
  1148
  
sl@0
  1149
  g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
sl@0
  1150
  g_return_if_fail (detailed_signal != NULL);
sl@0
  1151
  
sl@0
  1152
  SIGNAL_LOCK ();
sl@0
  1153
  itype = G_TYPE_FROM_INSTANCE (instance);
sl@0
  1154
  signal_id = signal_parse_name (detailed_signal, itype, &detail, TRUE);
sl@0
  1155
  if (signal_id)
sl@0
  1156
    {
sl@0
  1157
      SignalNode *node = LOOKUP_SIGNAL_NODE (signal_id);
sl@0
  1158
      
sl@0
  1159
      if (detail && !(node->flags & G_SIGNAL_DETAILED))
sl@0
  1160
	g_warning ("%s: signal `%s' does not support details", G_STRLOC, detailed_signal);
sl@0
  1161
      else if (!g_type_is_a (itype, node->itype))
sl@0
  1162
	g_warning ("%s: signal `%s' is invalid for instance `%p'", G_STRLOC, detailed_signal, instance);
sl@0
  1163
      else
sl@0
  1164
	{
sl@0
  1165
	  Emission *emission_list = node->flags & G_SIGNAL_NO_RECURSE ? g_restart_emissions : g_recursive_emissions;
sl@0
  1166
	  Emission *emission = emission_find (emission_list, signal_id, detail, instance);
sl@0
  1167
	  
sl@0
  1168
	  if (emission)
sl@0
  1169
	    {
sl@0
  1170
	      if (emission->state == EMISSION_HOOK)
sl@0
  1171
		g_warning (G_STRLOC ": emission of signal \"%s\" for instance `%p' cannot be stopped from emission hook",
sl@0
  1172
			   node->name, instance);
sl@0
  1173
	      else if (emission->state == EMISSION_RUN)
sl@0
  1174
		emission->state = EMISSION_STOP;
sl@0
  1175
	    }
sl@0
  1176
	  else
sl@0
  1177
	    g_warning (G_STRLOC ": no emission of signal \"%s\" to stop for instance `%p'",
sl@0
  1178
		       node->name, instance);
sl@0
  1179
	}
sl@0
  1180
    }
sl@0
  1181
  else
sl@0
  1182
    g_warning ("%s: signal `%s' is invalid for instance `%p'", G_STRLOC, detailed_signal, instance);
sl@0
  1183
  SIGNAL_UNLOCK ();
sl@0
  1184
}
sl@0
  1185
sl@0
  1186
/**
sl@0
  1187
 * g_signal_lookup:
sl@0
  1188
 * @name: the signal's name.
sl@0
  1189
 * @itype: the type that the signal operates on.
sl@0
  1190
 *
sl@0
  1191
 * Given the name of the signal and the type of object it connects to, gets
sl@0
  1192
 * the signal's identifying integer. Emitting the signal by number is
sl@0
  1193
 * somewhat faster than using the name each time.
sl@0
  1194
 *
sl@0
  1195
 * Also tries the ancestors of the given type.
sl@0
  1196
 *
sl@0
  1197
 * See g_signal_new() for details on allowed signal names.
sl@0
  1198
 *
sl@0
  1199
 * Returns: the signal's identifying number, or 0 if no signal was found.
sl@0
  1200
 */
sl@0
  1201
EXPORT_C guint
sl@0
  1202
g_signal_lookup (const gchar *name,
sl@0
  1203
                 GType        itype)
sl@0
  1204
{
sl@0
  1205
  guint signal_id;
sl@0
  1206
  g_return_val_if_fail (name != NULL, 0);
sl@0
  1207
  g_return_val_if_fail (G_TYPE_IS_INSTANTIATABLE (itype) || G_TYPE_IS_INTERFACE (itype), 0);
sl@0
  1208
  
sl@0
  1209
  SIGNAL_LOCK ();
sl@0
  1210
  signal_id = signal_id_lookup (g_quark_try_string (name), itype);
sl@0
  1211
  SIGNAL_UNLOCK ();
sl@0
  1212
  if (!signal_id)
sl@0
  1213
    {
sl@0
  1214
      /* give elaborate warnings */
sl@0
  1215
      if (!g_type_name (itype))
sl@0
  1216
	g_warning (G_STRLOC ": unable to lookup signal \"%s\" for invalid type id `%"G_GSIZE_FORMAT"'",
sl@0
  1217
		   name, itype);
sl@0
  1218
      else if (!G_TYPE_IS_INSTANTIATABLE (itype))
sl@0
  1219
	g_warning (G_STRLOC ": unable to lookup signal \"%s\" for non instantiatable type `%s'",
sl@0
  1220
		   name, g_type_name (itype));
sl@0
  1221
      else if (!g_type_class_peek (itype))
sl@0
  1222
	g_warning (G_STRLOC ": unable to lookup signal \"%s\" of unloaded type `%s'",
sl@0
  1223
		   name, g_type_name (itype));
sl@0
  1224
    }
sl@0
  1225
  
sl@0
  1226
  return signal_id;
sl@0
  1227
}
sl@0
  1228
sl@0
  1229
/**
sl@0
  1230
 * g_signal_list_ids:
sl@0
  1231
 * @itype: Instance or interface type.
sl@0
  1232
 * @n_ids: Location to store the number of signal ids for @itype.
sl@0
  1233
 *
sl@0
  1234
 * Lists the signals by id that a certain instance or interface type
sl@0
  1235
 * created. Further information about the signals can be acquired through
sl@0
  1236
 * g_signal_query().
sl@0
  1237
 *
sl@0
  1238
 * Returns: Newly allocated array of signal IDs.
sl@0
  1239
 */
sl@0
  1240
EXPORT_C guint*
sl@0
  1241
g_signal_list_ids (GType  itype,
sl@0
  1242
		   guint *n_ids)
sl@0
  1243
{
sl@0
  1244
  SignalKey *keys;
sl@0
  1245
  GArray *result;
sl@0
  1246
  guint n_nodes;
sl@0
  1247
  guint i;
sl@0
  1248
  
sl@0
  1249
  g_return_val_if_fail (G_TYPE_IS_INSTANTIATABLE (itype) || G_TYPE_IS_INTERFACE (itype), NULL);
sl@0
  1250
  g_return_val_if_fail (n_ids != NULL, NULL);
sl@0
  1251
  
sl@0
  1252
  SIGNAL_LOCK ();
sl@0
  1253
  keys = g_bsearch_array_get_nth (g_signal_key_bsa, &g_signal_key_bconfig, 0);
sl@0
  1254
  n_nodes = g_bsearch_array_get_n_nodes (g_signal_key_bsa);
sl@0
  1255
  result = g_array_new (FALSE, FALSE, sizeof (guint));
sl@0
  1256
  
sl@0
  1257
  for (i = 0; i < n_nodes; i++)
sl@0
  1258
    if (keys[i].itype == itype)
sl@0
  1259
      {
sl@0
  1260
	const gchar *name = g_quark_to_string (keys[i].quark);
sl@0
  1261
	
sl@0
  1262
	/* Signal names with "_" in them are aliases to the same
sl@0
  1263
	 * name with "-" instead of "_".
sl@0
  1264
	 */
sl@0
  1265
	if (!strchr (name, '_'))
sl@0
  1266
	  g_array_append_val (result, keys[i].signal_id);
sl@0
  1267
      }
sl@0
  1268
  *n_ids = result->len;
sl@0
  1269
  SIGNAL_UNLOCK ();
sl@0
  1270
  if (!n_nodes)
sl@0
  1271
    {
sl@0
  1272
      /* give elaborate warnings */
sl@0
  1273
      if (!g_type_name (itype))
sl@0
  1274
	g_warning (G_STRLOC ": unable to list signals for invalid type id `%"G_GSIZE_FORMAT"'",
sl@0
  1275
		   itype);
sl@0
  1276
      else if (!G_TYPE_IS_INSTANTIATABLE (itype) && !G_TYPE_IS_INTERFACE (itype))
sl@0
  1277
	g_warning (G_STRLOC ": unable to list signals of non instantiatable type `%s'",
sl@0
  1278
		   g_type_name (itype));
sl@0
  1279
      else if (!g_type_class_peek (itype) && !G_TYPE_IS_INTERFACE (itype))
sl@0
  1280
	g_warning (G_STRLOC ": unable to list signals of unloaded type `%s'",
sl@0
  1281
		   g_type_name (itype));
sl@0
  1282
    }
sl@0
  1283
  
sl@0
  1284
  return (guint*) g_array_free (result, FALSE);
sl@0
  1285
}
sl@0
  1286
sl@0
  1287
/**
sl@0
  1288
 * g_signal_name:
sl@0
  1289
 * @signal_id: the signal's identifying number.
sl@0
  1290
 *
sl@0
  1291
 * Given the signal's identifier, finds its name.
sl@0
  1292
 *
sl@0
  1293
 * Two different signals may have the same name, if they have differing types.
sl@0
  1294
 *
sl@0
  1295
 * Returns: the signal name, or %NULL if the signal number was invalid.
sl@0
  1296
 */
sl@0
  1297
EXPORT_C G_CONST_RETURN gchar*
sl@0
  1298
g_signal_name (guint signal_id)
sl@0
  1299
{
sl@0
  1300
  SignalNode *node;
sl@0
  1301
  const gchar *name;
sl@0
  1302
  
sl@0
  1303
  SIGNAL_LOCK ();
sl@0
  1304
  node = LOOKUP_SIGNAL_NODE (signal_id);
sl@0
  1305
  name = node ? node->name : NULL;
sl@0
  1306
  SIGNAL_UNLOCK ();
sl@0
  1307
  
sl@0
  1308
  return (char*) name;
sl@0
  1309
}
sl@0
  1310
sl@0
  1311
/**
sl@0
  1312
 * g_signal_query:
sl@0
  1313
 * @signal_id: The signal id of the signal to query information for.
sl@0
  1314
 * @query: A user provided structure that is filled in with constant
sl@0
  1315
 *  values upon success.
sl@0
  1316
 *
sl@0
  1317
 * Queries the signal system for in-depth information about a
sl@0
  1318
 * specific signal. This function will fill in a user-provided
sl@0
  1319
 * structure to hold signal-specific information. If an invalid
sl@0
  1320
 * signal id is passed in, the @signal_id member of the #GSignalQuery
sl@0
  1321
 * is 0. All members filled into the #GSignalQuery structure should
sl@0
  1322
 * be considered constant and have to be left untouched.
sl@0
  1323
 */
sl@0
  1324
EXPORT_C void
sl@0
  1325
g_signal_query (guint         signal_id,
sl@0
  1326
		GSignalQuery *query)
sl@0
  1327
{
sl@0
  1328
  SignalNode *node;
sl@0
  1329
  
sl@0
  1330
  g_return_if_fail (query != NULL);
sl@0
  1331
  
sl@0
  1332
  SIGNAL_LOCK ();
sl@0
  1333
  node = LOOKUP_SIGNAL_NODE (signal_id);
sl@0
  1334
  if (!node || node->destroyed)
sl@0
  1335
    query->signal_id = 0;
sl@0
  1336
  else
sl@0
  1337
    {
sl@0
  1338
      query->signal_id = node->signal_id;
sl@0
  1339
      query->signal_name = node->name;
sl@0
  1340
      query->itype = node->itype;
sl@0
  1341
      query->signal_flags = node->flags;
sl@0
  1342
      query->return_type = node->return_type;
sl@0
  1343
      query->n_params = node->n_params;
sl@0
  1344
      query->param_types = node->param_types;
sl@0
  1345
    }
sl@0
  1346
  SIGNAL_UNLOCK ();
sl@0
  1347
}
sl@0
  1348
sl@0
  1349
/**
sl@0
  1350
 * g_signal_new:
sl@0
  1351
 * @signal_name: the name for the signal
sl@0
  1352
 * @itype: the type this signal pertains to. It will also pertain to
sl@0
  1353
 *  types which are derived from this type.
sl@0
  1354
 * @signal_flags: a combination of #GSignalFlags specifying detail of when
sl@0
  1355
 *  the default handler is to be invoked. You should at least specify
sl@0
  1356
 *  %G_SIGNAL_RUN_FIRST or %G_SIGNAL_RUN_LAST.
sl@0
  1357
 * @class_offset: The offset of the function pointer in the class structure
sl@0
  1358
 *  for this type. Used to invoke a class method generically. Pass 0 to
sl@0
  1359
 *  not associate a class method with this signal.
sl@0
  1360
 * @accumulator: the accumulator for this signal; may be %NULL.
sl@0
  1361
 * @accu_data: user data for the @accumulator.
sl@0
  1362
 * @c_marshaller: the function to translate arrays of parameter values to
sl@0
  1363
 *  signal emissions into C language callback invocations.
sl@0
  1364
 * @return_type: the type of return value, or #G_TYPE_NONE for a signal
sl@0
  1365
 *  without a return value.
sl@0
  1366
 * @n_params: the number of parameter types to follow.
sl@0
  1367
 * @...: a list of types, one for each parameter.
sl@0
  1368
 *
sl@0
  1369
 * Creates a new signal. (This is usually done in the class initializer.)
sl@0
  1370
 *
sl@0
  1371
 * A signal name consists of segments consisting of ASCII letters and
sl@0
  1372
 * digits, separated by either the '-' or '_' character. The first
sl@0
  1373
 * character of a signal name must be a letter. Names which violate these
sl@0
  1374
 * rules lead to undefined behaviour of the GSignal system.
sl@0
  1375
 *
sl@0
  1376
 * When registering a signal and looking up a signal, either separator can
sl@0
  1377
 * be used, but they cannot be mixed.
sl@0
  1378
 *
sl@0
  1379
 * Returns: the signal id
sl@0
  1380
 */
sl@0
  1381
EXPORT_C guint
sl@0
  1382
g_signal_new (const gchar	 *signal_name,
sl@0
  1383
	      GType		  itype,
sl@0
  1384
	      GSignalFlags	  signal_flags,
sl@0
  1385
	      guint               class_offset,
sl@0
  1386
	      GSignalAccumulator  accumulator,
sl@0
  1387
	      gpointer		  accu_data,
sl@0
  1388
	      GSignalCMarshaller  c_marshaller,
sl@0
  1389
	      GType		  return_type,
sl@0
  1390
	      guint		  n_params,
sl@0
  1391
	      ...)
sl@0
  1392
{
sl@0
  1393
  va_list args;
sl@0
  1394
  guint signal_id;
sl@0
  1395
sl@0
  1396
  g_return_val_if_fail (signal_name != NULL, 0);
sl@0
  1397
  
sl@0
  1398
  va_start (args, n_params);
sl@0
  1399
sl@0
  1400
  signal_id = g_signal_new_valist (signal_name, itype, signal_flags,
sl@0
  1401
                                   class_offset ? g_signal_type_cclosure_new (itype, class_offset) : NULL,
sl@0
  1402
				   accumulator, accu_data, c_marshaller,
sl@0
  1403
                                   return_type, n_params, args);
sl@0
  1404
sl@0
  1405
  va_end (args);
sl@0
  1406
sl@0
  1407
  /* optimize NOP emissions with NULL class handlers */
sl@0
  1408
  if (signal_id && G_TYPE_IS_INSTANTIATABLE (itype) && return_type == G_TYPE_NONE &&
sl@0
  1409
      class_offset && class_offset < MAX_TEST_CLASS_OFFSET)
sl@0
  1410
    {
sl@0
  1411
      SignalNode *node;
sl@0
  1412
sl@0
  1413
      SIGNAL_LOCK ();
sl@0
  1414
      node = LOOKUP_SIGNAL_NODE (signal_id);
sl@0
  1415
      node->test_class_offset = class_offset;
sl@0
  1416
      SIGNAL_UNLOCK ();
sl@0
  1417
    }
sl@0
  1418
 
sl@0
  1419
  return signal_id;
sl@0
  1420
}
sl@0
  1421
sl@0
  1422
/**
sl@0
  1423
 * g_signal_new_class_handler:
sl@0
  1424
 * @signal_name: the name for the signal
sl@0
  1425
 * @itype: the type this signal pertains to. It will also pertain to
sl@0
  1426
 *  types which are derived from this type.
sl@0
  1427
 * @signal_flags: a combination of #GSignalFlags specifying detail of when
sl@0
  1428
 *  the default handler is to be invoked. You should at least specify
sl@0
  1429
 *  %G_SIGNAL_RUN_FIRST or %G_SIGNAL_RUN_LAST.
sl@0
  1430
 * @class_handler: a #GCallback which acts as class implementation of
sl@0
  1431
 *  this signal. Used to invoke a class method generically. Pass %NULL to
sl@0
  1432
 *  not associate a class method with this signal.
sl@0
  1433
 * @accumulator: the accumulator for this signal; may be %NULL.
sl@0
  1434
 * @accu_data: user data for the @accumulator.
sl@0
  1435
 * @c_marshaller: the function to translate arrays of parameter values to
sl@0
  1436
 *  signal emissions into C language callback invocations.
sl@0
  1437
 * @return_type: the type of return value, or #G_TYPE_NONE for a signal
sl@0
  1438
 *  without a return value.
sl@0
  1439
 * @n_params: the number of parameter types to follow.
sl@0
  1440
 * @...: a list of types, one for each parameter.
sl@0
  1441
 *
sl@0
  1442
 * Creates a new signal. (This is usually done in the class initializer.)
sl@0
  1443
 *
sl@0
  1444
 * This is a variant of g_signal_new() that takes a C callback instead
sl@0
  1445
 * off a class offset for the signal's class handler. This function
sl@0
  1446
 * doesn't need a function pointer exposed in the class structure of
sl@0
  1447
 * an object definition, instead the function pointer is passed
sl@0
  1448
 * directly and can be overriden by derived classes with
sl@0
  1449
 * g_signal_override_class_closure() or
sl@0
  1450
 * g_signal_override_class_handler()and chained to with
sl@0
  1451
 * g_signal_chain_from_overridden() or
sl@0
  1452
 * g_signal_chain_from_overridden_handler().
sl@0
  1453
 *
sl@0
  1454
 * See g_signal_new() for information about signal names.
sl@0
  1455
 *
sl@0
  1456
 * Returns: the signal id
sl@0
  1457
 *
sl@0
  1458
 * Since: 2.18
sl@0
  1459
 */
sl@0
  1460
EXPORT_C guint
sl@0
  1461
g_signal_new_class_handler (const gchar        *signal_name,
sl@0
  1462
                            GType               itype,
sl@0
  1463
                            GSignalFlags        signal_flags,
sl@0
  1464
                            GCallback           class_handler,
sl@0
  1465
                            GSignalAccumulator  accumulator,
sl@0
  1466
                            gpointer            accu_data,
sl@0
  1467
                            GSignalCMarshaller  c_marshaller,
sl@0
  1468
                            GType               return_type,
sl@0
  1469
                            guint               n_params,
sl@0
  1470
                            ...)
sl@0
  1471
{
sl@0
  1472
  va_list args;
sl@0
  1473
  guint signal_id;
sl@0
  1474
sl@0
  1475
  g_return_val_if_fail (signal_name != NULL, 0);
sl@0
  1476
sl@0
  1477
  va_start (args, n_params);
sl@0
  1478
sl@0
  1479
  signal_id = g_signal_new_valist (signal_name, itype, signal_flags,
sl@0
  1480
                                   class_handler ? g_cclosure_new (class_handler, NULL, NULL) : NULL,
sl@0
  1481
                                   accumulator, accu_data, c_marshaller,
sl@0
  1482
                                   return_type, n_params, args);
sl@0
  1483
sl@0
  1484
  va_end (args);
sl@0
  1485
sl@0
  1486
  return signal_id;
sl@0
  1487
}
sl@0
  1488
sl@0
  1489
static inline ClassClosure*
sl@0
  1490
signal_find_class_closure (SignalNode *node,
sl@0
  1491
			   GType       itype)
sl@0
  1492
{
sl@0
  1493
  GBSearchArray *bsa = node->class_closure_bsa;
sl@0
  1494
  ClassClosure *cc;
sl@0
  1495
sl@0
  1496
  if (bsa)
sl@0
  1497
    {
sl@0
  1498
      ClassClosure key;
sl@0
  1499
sl@0
  1500
      /* cc->instance_type is 0 for default closure */
sl@0
  1501
      
sl@0
  1502
      key.instance_type = itype;
sl@0
  1503
      cc = g_bsearch_array_lookup (bsa, &g_class_closure_bconfig, &key);
sl@0
  1504
      while (!cc && key.instance_type)
sl@0
  1505
	{
sl@0
  1506
	  key.instance_type = g_type_parent (key.instance_type);
sl@0
  1507
	  cc = g_bsearch_array_lookup (bsa, &g_class_closure_bconfig, &key);
sl@0
  1508
	}
sl@0
  1509
    }
sl@0
  1510
  else
sl@0
  1511
    cc = NULL;
sl@0
  1512
  return cc;
sl@0
  1513
}
sl@0
  1514
sl@0
  1515
static inline GClosure*
sl@0
  1516
signal_lookup_closure (SignalNode    *node,
sl@0
  1517
		       GTypeInstance *instance)
sl@0
  1518
{
sl@0
  1519
  ClassClosure *cc;
sl@0
  1520
sl@0
  1521
  if (node->class_closure_bsa && g_bsearch_array_get_n_nodes (node->class_closure_bsa) == 1)
sl@0
  1522
    {
sl@0
  1523
      cc = g_bsearch_array_get_nth (node->class_closure_bsa, &g_class_closure_bconfig, 0);
sl@0
  1524
      if (cc && cc->instance_type == 0) /* check for default closure */
sl@0
  1525
        return cc->closure;
sl@0
  1526
    }
sl@0
  1527
  cc = signal_find_class_closure (node, G_TYPE_FROM_INSTANCE (instance));
sl@0
  1528
  return cc ? cc->closure : NULL;
sl@0
  1529
}
sl@0
  1530
sl@0
  1531
static void
sl@0
  1532
signal_add_class_closure (SignalNode *node,
sl@0
  1533
			  GType       itype,
sl@0
  1534
			  GClosure   *closure)
sl@0
  1535
{
sl@0
  1536
  ClassClosure key;
sl@0
  1537
sl@0
  1538
  /* can't optimize NOP emissions with overridden class closures */
sl@0
  1539
  node->test_class_offset = 0;
sl@0
  1540
sl@0
  1541
  if (!node->class_closure_bsa)
sl@0
  1542
    node->class_closure_bsa = g_bsearch_array_create (&g_class_closure_bconfig);
sl@0
  1543
  key.instance_type = itype;
sl@0
  1544
  key.closure = g_closure_ref (closure);
sl@0
  1545
  node->class_closure_bsa = g_bsearch_array_insert (node->class_closure_bsa,
sl@0
  1546
						    &g_class_closure_bconfig,
sl@0
  1547
						    &key);
sl@0
  1548
  g_closure_sink (closure);
sl@0
  1549
  if (node->c_marshaller && closure && G_CLOSURE_NEEDS_MARSHAL (closure))
sl@0
  1550
    g_closure_set_marshal (closure, node->c_marshaller);
sl@0
  1551
}
sl@0
  1552
sl@0
  1553
/**
sl@0
  1554
 * g_signal_newv:
sl@0
  1555
 * @signal_name: the name for the signal
sl@0
  1556
 * @itype: the type this signal pertains to. It will also pertain to
sl@0
  1557
 *     types which are derived from this type
sl@0
  1558
 * @signal_flags: a combination of #GSignalFlags specifying detail of when
sl@0
  1559
 *     the default handler is to be invoked. You should at least specify
sl@0
  1560
 *     %G_SIGNAL_RUN_FIRST or %G_SIGNAL_RUN_LAST
sl@0
  1561
 * @class_closure: The closure to invoke on signal emission; may be %NULL
sl@0
  1562
 * @accumulator: the accumulator for this signal; may be %NULL
sl@0
  1563
 * @accu_data: user data for the @accumulator
sl@0
  1564
 * @c_marshaller: the function to translate arrays of parameter values to
sl@0
  1565
 *     signal emissions into C language callback invocations
sl@0
  1566
 * @return_type: the type of return value, or #G_TYPE_NONE for a signal
sl@0
  1567
 *     without a return value
sl@0
  1568
 * @n_params: the length of @param_types
sl@0
  1569
 * @param_types: an array of types, one for each parameter
sl@0
  1570
 *
sl@0
  1571
 * Creates a new signal. (This is usually done in the class initializer.)
sl@0
  1572
 *
sl@0
  1573
 * See g_signal_new() for details on allowed signal names.
sl@0
  1574
 *
sl@0
  1575
 * Returns: the signal id
sl@0
  1576
 */
sl@0
  1577
EXPORT_C guint
sl@0
  1578
g_signal_newv (const gchar       *signal_name,
sl@0
  1579
               GType              itype,
sl@0
  1580
               GSignalFlags       signal_flags,
sl@0
  1581
               GClosure          *class_closure,
sl@0
  1582
               GSignalAccumulator accumulator,
sl@0
  1583
	       gpointer		  accu_data,
sl@0
  1584
               GSignalCMarshaller c_marshaller,
sl@0
  1585
               GType		  return_type,
sl@0
  1586
               guint              n_params,
sl@0
  1587
               GType		 *param_types)
sl@0
  1588
{
sl@0
  1589
  gchar *name;
sl@0
  1590
  guint signal_id, i;
sl@0
  1591
  SignalNode *node;
sl@0
  1592
  
sl@0
  1593
  g_return_val_if_fail (signal_name != NULL, 0);
sl@0
  1594
  g_return_val_if_fail (G_TYPE_IS_INSTANTIATABLE (itype) || G_TYPE_IS_INTERFACE (itype), 0);
sl@0
  1595
  if (n_params)
sl@0
  1596
    g_return_val_if_fail (param_types != NULL, 0);
sl@0
  1597
  g_return_val_if_fail ((return_type & G_SIGNAL_TYPE_STATIC_SCOPE) == 0, 0);
sl@0
  1598
  if (return_type == (G_TYPE_NONE & ~G_SIGNAL_TYPE_STATIC_SCOPE))
sl@0
  1599
    g_return_val_if_fail (accumulator == NULL, 0);
sl@0
  1600
  if (!accumulator)
sl@0
  1601
    g_return_val_if_fail (accu_data == NULL, 0);
sl@0
  1602
sl@0
  1603
  name = g_strdup (signal_name);
sl@0
  1604
  g_strdelimit (name, G_STR_DELIMITERS ":^", '_');  /* FIXME do character checks like for types */
sl@0
  1605
  
sl@0
  1606
  SIGNAL_LOCK ();
sl@0
  1607
  
sl@0
  1608
  signal_id = signal_id_lookup (g_quark_try_string (name), itype);
sl@0
  1609
  node = LOOKUP_SIGNAL_NODE (signal_id);
sl@0
  1610
  if (node && !node->destroyed)
sl@0
  1611
    {
sl@0
  1612
      g_warning (G_STRLOC ": signal \"%s\" already exists in the `%s' %s",
sl@0
  1613
                 name,
sl@0
  1614
                 type_debug_name (node->itype),
sl@0
  1615
                 G_TYPE_IS_INTERFACE (node->itype) ? "interface" : "class ancestry");
sl@0
  1616
      g_free (name);
sl@0
  1617
      SIGNAL_UNLOCK ();
sl@0
  1618
      return 0;
sl@0
  1619
    }
sl@0
  1620
  if (node && node->itype != itype)
sl@0
  1621
    {
sl@0
  1622
      g_warning (G_STRLOC ": signal \"%s\" for type `%s' was previously created for type `%s'",
sl@0
  1623
                 name,
sl@0
  1624
                 type_debug_name (itype),
sl@0
  1625
                 type_debug_name (node->itype));
sl@0
  1626
      g_free (name);
sl@0
  1627
      SIGNAL_UNLOCK ();
sl@0
  1628
      return 0;
sl@0
  1629
    }
sl@0
  1630
  for (i = 0; i < n_params; i++)
sl@0
  1631
    if (!G_TYPE_IS_VALUE (param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE))
sl@0
  1632
      {
sl@0
  1633
	g_warning (G_STRLOC ": parameter %d of type `%s' for signal \"%s::%s\" is not a value type",
sl@0
  1634
		   i + 1, type_debug_name (param_types[i]), type_debug_name (itype), name);
sl@0
  1635
	g_free (name);
sl@0
  1636
	SIGNAL_UNLOCK ();
sl@0
  1637
	return 0;
sl@0
  1638
      }
sl@0
  1639
  if (return_type != G_TYPE_NONE && !G_TYPE_IS_VALUE (return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE))
sl@0
  1640
    {
sl@0
  1641
      g_warning (G_STRLOC ": return value of type `%s' for signal \"%s::%s\" is not a value type",
sl@0
  1642
		 type_debug_name (return_type), type_debug_name (itype), name);
sl@0
  1643
      g_free (name);
sl@0
  1644
      SIGNAL_UNLOCK ();
sl@0
  1645
      return 0;
sl@0
  1646
    }
sl@0
  1647
  if (return_type != G_TYPE_NONE &&
sl@0
  1648
      (signal_flags & (G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST | G_SIGNAL_RUN_CLEANUP)) == G_SIGNAL_RUN_FIRST)
sl@0
  1649
    {
sl@0
  1650
      g_warning (G_STRLOC ": signal \"%s::%s\" has return type `%s' and is only G_SIGNAL_RUN_FIRST",
sl@0
  1651
		 type_debug_name (itype), name, type_debug_name (return_type));
sl@0
  1652
      g_free (name);
sl@0
  1653
      SIGNAL_UNLOCK ();
sl@0
  1654
      return 0;
sl@0
  1655
    }
sl@0
  1656
  
sl@0
  1657
  /* setup permanent portion of signal node */
sl@0
  1658
  if (!node)
sl@0
  1659
    {
sl@0
  1660
      SignalKey key;
sl@0
  1661
      
sl@0
  1662
      signal_id = g_n_signal_nodes++;
sl@0
  1663
      node = g_new (SignalNode, 1);
sl@0
  1664
      node->signal_id = signal_id;
sl@0
  1665
      g_signal_nodes = g_renew (SignalNode*, g_signal_nodes, g_n_signal_nodes);
sl@0
  1666
      g_signal_nodes[signal_id] = node;
sl@0
  1667
      node->itype = itype;
sl@0
  1668
      node->name = name;
sl@0
  1669
      key.itype = itype;
sl@0
  1670
      key.quark = g_quark_from_string (node->name);
sl@0
  1671
      key.signal_id = signal_id;
sl@0
  1672
      g_signal_key_bsa = g_bsearch_array_insert (g_signal_key_bsa, &g_signal_key_bconfig, &key);
sl@0
  1673
      g_strdelimit (name, "_", '-');
sl@0
  1674
      node->name = g_intern_string (name);
sl@0
  1675
      key.quark = g_quark_from_string (name);
sl@0
  1676
      g_signal_key_bsa = g_bsearch_array_insert (g_signal_key_bsa, &g_signal_key_bconfig, &key);
sl@0
  1677
    }
sl@0
  1678
  node->destroyed = FALSE;
sl@0
  1679
  node->test_class_offset = 0;
sl@0
  1680
sl@0
  1681
  /* setup reinitializable portion */
sl@0
  1682
  node->flags = signal_flags & G_SIGNAL_FLAGS_MASK;
sl@0
  1683
  node->n_params = n_params;
sl@0
  1684
  node->param_types = g_memdup (param_types, sizeof (GType) * n_params);
sl@0
  1685
  node->return_type = return_type;
sl@0
  1686
  node->class_closure_bsa = NULL;
sl@0
  1687
  if (accumulator)
sl@0
  1688
    {
sl@0
  1689
      node->accumulator = g_new (SignalAccumulator, 1);
sl@0
  1690
      node->accumulator->func = accumulator;
sl@0
  1691
      node->accumulator->data = accu_data;
sl@0
  1692
    }
sl@0
  1693
  else
sl@0
  1694
    node->accumulator = NULL;
sl@0
  1695
  node->c_marshaller = c_marshaller;
sl@0
  1696
  node->emission_hooks = NULL;
sl@0
  1697
  if (class_closure)
sl@0
  1698
    signal_add_class_closure (node, 0, class_closure);
sl@0
  1699
  else if (G_TYPE_IS_INSTANTIATABLE (itype) && return_type == G_TYPE_NONE)
sl@0
  1700
    {
sl@0
  1701
      /* optimize NOP emissions */
sl@0
  1702
      node->test_class_offset = TEST_CLASS_MAGIC;
sl@0
  1703
    }
sl@0
  1704
  SIGNAL_UNLOCK ();
sl@0
  1705
sl@0
  1706
  g_free (name);
sl@0
  1707
sl@0
  1708
  return signal_id;
sl@0
  1709
}
sl@0
  1710
sl@0
  1711
/**
sl@0
  1712
 * g_signal_new_valist:
sl@0
  1713
 * @signal_name: the name for the signal
sl@0
  1714
 * @itype: the type this signal pertains to. It will also pertain to
sl@0
  1715
 *  types which are derived from this type.
sl@0
  1716
 * @signal_flags: a combination of #GSignalFlags specifying detail of when
sl@0
  1717
 *  the default handler is to be invoked. You should at least specify
sl@0
  1718
 *  %G_SIGNAL_RUN_FIRST or %G_SIGNAL_RUN_LAST.
sl@0
  1719
 * @class_closure: The closure to invoke on signal emission; may be %NULL.
sl@0
  1720
 * @accumulator: the accumulator for this signal; may be %NULL.
sl@0
  1721
 * @accu_data: user data for the @accumulator.
sl@0
  1722
 * @c_marshaller: the function to translate arrays of parameter values to
sl@0
  1723
 *  signal emissions into C language callback invocations.
sl@0
  1724
 * @return_type: the type of return value, or #G_TYPE_NONE for a signal
sl@0
  1725
 *  without a return value.
sl@0
  1726
 * @n_params: the number of parameter types in @args.
sl@0
  1727
 * @args: va_list of #GType, one for each parameter.
sl@0
  1728
 *
sl@0
  1729
 * Creates a new signal. (This is usually done in the class initializer.)
sl@0
  1730
 *
sl@0
  1731
 * See g_signal_new() for details on allowed signal names.
sl@0
  1732
 *
sl@0
  1733
 * Returns: the signal id
sl@0
  1734
 */
sl@0
  1735
EXPORT_C guint
sl@0
  1736
g_signal_new_valist (const gchar       *signal_name,
sl@0
  1737
                     GType              itype,
sl@0
  1738
                     GSignalFlags       signal_flags,
sl@0
  1739
                     GClosure          *class_closure,
sl@0
  1740
                     GSignalAccumulator accumulator,
sl@0
  1741
		     gpointer		accu_data,
sl@0
  1742
                     GSignalCMarshaller c_marshaller,
sl@0
  1743
                     GType              return_type,
sl@0
  1744
                     guint              n_params,
sl@0
  1745
                     va_list            args)
sl@0
  1746
{
sl@0
  1747
  GType *param_types;
sl@0
  1748
  guint i;
sl@0
  1749
  guint signal_id;
sl@0
  1750
sl@0
  1751
  if (n_params > 0)
sl@0
  1752
    {
sl@0
  1753
      param_types = g_new (GType, n_params);
sl@0
  1754
sl@0
  1755
      for (i = 0; i < n_params; i++)
sl@0
  1756
	param_types[i] = va_arg (args, GType);
sl@0
  1757
    }
sl@0
  1758
  else
sl@0
  1759
    param_types = NULL;
sl@0
  1760
sl@0
  1761
  signal_id = g_signal_newv (signal_name, itype, signal_flags,
sl@0
  1762
			     class_closure, accumulator, accu_data, c_marshaller,
sl@0
  1763
			     return_type, n_params, param_types);
sl@0
  1764
  g_free (param_types);
sl@0
  1765
sl@0
  1766
  return signal_id;
sl@0
  1767
}
sl@0
  1768
sl@0
  1769
static void
sl@0
  1770
signal_destroy_R (SignalNode *signal_node)
sl@0
  1771
{
sl@0
  1772
  SignalNode node = *signal_node;
sl@0
  1773
sl@0
  1774
  signal_node->destroyed = TRUE;
sl@0
  1775
  
sl@0
  1776
  /* reentrancy caution, zero out real contents first */
sl@0
  1777
  signal_node->test_class_offset = 0;
sl@0
  1778
  signal_node->n_params = 0;
sl@0
  1779
  signal_node->param_types = NULL;
sl@0
  1780
  signal_node->return_type = 0;
sl@0
  1781
  signal_node->class_closure_bsa = NULL;
sl@0
  1782
  signal_node->accumulator = NULL;
sl@0
  1783
  signal_node->c_marshaller = NULL;
sl@0
  1784
  signal_node->emission_hooks = NULL;
sl@0
  1785
  
sl@0
  1786
#ifdef	G_ENABLE_DEBUG
sl@0
  1787
  /* check current emissions */
sl@0
  1788
  {
sl@0
  1789
    Emission *emission;
sl@0
  1790
    
sl@0
  1791
    for (emission = (node.flags & G_SIGNAL_NO_RECURSE) ? g_restart_emissions : g_recursive_emissions;
sl@0
  1792
         emission; emission = emission->next)
sl@0
  1793
      if (emission->ihint.signal_id == node.signal_id)
sl@0
  1794
        g_critical (G_STRLOC ": signal \"%s\" being destroyed is currently in emission (instance `%p')",
sl@0
  1795
                    node.name, emission->instance);
sl@0
  1796
  }
sl@0
  1797
#endif
sl@0
  1798
  
sl@0
  1799
  /* free contents that need to
sl@0
  1800
   */
sl@0
  1801
  SIGNAL_UNLOCK ();
sl@0
  1802
  g_free (node.param_types);
sl@0
  1803
  if (node.class_closure_bsa)
sl@0
  1804
    {
sl@0
  1805
      guint i;
sl@0
  1806
sl@0
  1807
      for (i = 0; i < node.class_closure_bsa->n_nodes; i++)
sl@0
  1808
	{
sl@0
  1809
	  ClassClosure *cc = g_bsearch_array_get_nth (node.class_closure_bsa, &g_class_closure_bconfig, i);
sl@0
  1810
sl@0
  1811
	  g_closure_unref (cc->closure);
sl@0
  1812
	}
sl@0
  1813
      g_bsearch_array_free (node.class_closure_bsa, &g_class_closure_bconfig);
sl@0
  1814
    }
sl@0
  1815
  g_free (node.accumulator);
sl@0
  1816
  if (node.emission_hooks)
sl@0
  1817
    {
sl@0
  1818
      g_hook_list_clear (node.emission_hooks);
sl@0
  1819
      g_free (node.emission_hooks);
sl@0
  1820
    }
sl@0
  1821
  SIGNAL_LOCK ();
sl@0
  1822
}
sl@0
  1823
sl@0
  1824
/**
sl@0
  1825
 * g_signal_override_class_closure:
sl@0
  1826
 * @signal_id: the signal id
sl@0
  1827
 * @instance_type: the instance type on which to override the class closure
sl@0
  1828
 *  for the signal.
sl@0
  1829
 * @class_closure: the closure.
sl@0
  1830
 *
sl@0
  1831
 * Overrides the class closure (i.e. the default handler) for the given signal
sl@0
  1832
 * for emissions on instances of @instance_type. @instance_type must be derived
sl@0
  1833
 * from the type to which the signal belongs.
sl@0
  1834
 *
sl@0
  1835
 * See g_signal_chain_from_overridden() and
sl@0
  1836
 * g_signal_chain_from_overridden_handler() for how to chain up to the
sl@0
  1837
 * parent class closure from inside the overridden one.
sl@0
  1838
 */
sl@0
  1839
EXPORT_C void
sl@0
  1840
g_signal_override_class_closure (guint     signal_id,
sl@0
  1841
				 GType     instance_type,
sl@0
  1842
				 GClosure *class_closure)
sl@0
  1843
{
sl@0
  1844
  SignalNode *node;
sl@0
  1845
  
sl@0
  1846
  g_return_if_fail (signal_id > 0);
sl@0
  1847
  g_return_if_fail (class_closure != NULL);
sl@0
  1848
  
sl@0
  1849
  SIGNAL_LOCK ();
sl@0
  1850
  node = LOOKUP_SIGNAL_NODE (signal_id);
sl@0
  1851
  if (!g_type_is_a (instance_type, node->itype))
sl@0
  1852
    g_warning ("%s: type `%s' cannot be overridden for signal id `%u'", G_STRLOC, type_debug_name (instance_type), signal_id);
sl@0
  1853
  else
sl@0
  1854
    {
sl@0
  1855
      ClassClosure *cc = signal_find_class_closure (node, instance_type);
sl@0
  1856
      
sl@0
  1857
      if (cc && cc->instance_type == instance_type)
sl@0
  1858
	g_warning ("%s: type `%s' is already overridden for signal id `%u'", G_STRLOC, type_debug_name (instance_type), signal_id);
sl@0
  1859
      else
sl@0
  1860
	signal_add_class_closure (node, instance_type, class_closure);
sl@0
  1861
    }
sl@0
  1862
  SIGNAL_UNLOCK ();
sl@0
  1863
}
sl@0
  1864
sl@0
  1865
/**
sl@0
  1866
 * g_signal_override_class_handler:
sl@0
  1867
 * @signal_name: the name for the signal
sl@0
  1868
 * @instance_type: the instance type on which to override the class handler
sl@0
  1869
 *  for the signal.
sl@0
  1870
 * @class_handler: the handler.
sl@0
  1871
 *
sl@0
  1872
 * Overrides the class closure (i.e. the default handler) for the
sl@0
  1873
 * given signal for emissions on instances of @instance_type with
sl@0
  1874
 * callabck @class_handler. @instance_type must be derived from the
sl@0
  1875
 * type to which the signal belongs.
sl@0
  1876
 *
sl@0
  1877
 * See g_signal_chain_from_overridden() and
sl@0
  1878
 * g_signal_chain_from_overridden_handler() for how to chain up to the
sl@0
  1879
 * parent class closure from inside the overridden one.
sl@0
  1880
 *
sl@0
  1881
 * Since: 2.18
sl@0
  1882
 */
sl@0
  1883
EXPORT_C void
sl@0
  1884
g_signal_override_class_handler (const gchar *signal_name,
sl@0
  1885
				 GType        instance_type,
sl@0
  1886
				 GCallback    class_handler)
sl@0
  1887
{
sl@0
  1888
  guint signal_id;
sl@0
  1889
sl@0
  1890
  g_return_if_fail (signal_name != NULL);
sl@0
  1891
  g_return_if_fail (instance_type != G_TYPE_NONE);
sl@0
  1892
  g_return_if_fail (class_handler != NULL);
sl@0
  1893
sl@0
  1894
  signal_id = g_signal_lookup (signal_name, instance_type);
sl@0
  1895
sl@0
  1896
  if (signal_id)
sl@0
  1897
    g_signal_override_class_closure (signal_id, instance_type,
sl@0
  1898
                                     g_cclosure_new (class_handler, NULL, NULL));
sl@0
  1899
  else
sl@0
  1900
    g_warning ("%s: signal name '%s' is invalid for type id '%"G_GSIZE_FORMAT"'",
sl@0
  1901
               G_STRLOC, signal_name, instance_type);
sl@0
  1902
sl@0
  1903
}
sl@0
  1904
sl@0
  1905
/**
sl@0
  1906
 * g_signal_chain_from_overridden:
sl@0
  1907
 * @instance_and_params: the argument list of the signal emission. The first
sl@0
  1908
 *  element in the array is a #GValue for the instance the signal is being
sl@0
  1909
 *  emitted on. The rest are any arguments to be passed to the signal.
sl@0
  1910
 * @return_value: Location for the return value.
sl@0
  1911
 *
sl@0
  1912
 * Calls the original class closure of a signal. This function should only
sl@0
  1913
 * be called from an overridden class closure; see
sl@0
  1914
 * g_signal_override_class_closure() and
sl@0
  1915
 * g_signal_override_class_handler().
sl@0
  1916
 */
sl@0
  1917
EXPORT_C void
sl@0
  1918
g_signal_chain_from_overridden (const GValue *instance_and_params,
sl@0
  1919
				GValue       *return_value)
sl@0
  1920
{
sl@0
  1921
  GType chain_type = 0, restore_type = 0;
sl@0
  1922
  Emission *emission = NULL;
sl@0
  1923
  GClosure *closure = NULL;
sl@0
  1924
  guint n_params = 0;
sl@0
  1925
  gpointer instance;
sl@0
  1926
  
sl@0
  1927
  g_return_if_fail (instance_and_params != NULL);
sl@0
  1928
  instance = g_value_peek_pointer (instance_and_params);
sl@0
  1929
  g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
sl@0
  1930
  
sl@0
  1931
  SIGNAL_LOCK ();
sl@0
  1932
  emission = emission_find_innermost (instance);
sl@0
  1933
  if (emission)
sl@0
  1934
    {
sl@0
  1935
      SignalNode *node = LOOKUP_SIGNAL_NODE (emission->ihint.signal_id);
sl@0
  1936
      
sl@0
  1937
      g_assert (node != NULL);	/* paranoid */
sl@0
  1938
      
sl@0
  1939
      /* we should probably do the same parameter checks as g_signal_emit() here.
sl@0
  1940
       */
sl@0
  1941
      if (emission->chain_type != G_TYPE_NONE)
sl@0
  1942
	{
sl@0
  1943
	  ClassClosure *cc = signal_find_class_closure (node, emission->chain_type);
sl@0
  1944
	  
sl@0
  1945
	  g_assert (cc != NULL);	/* closure currently in call stack */
sl@0
  1946
sl@0
  1947
	  n_params = node->n_params;
sl@0
  1948
	  restore_type = cc->instance_type;
sl@0
  1949
	  cc = signal_find_class_closure (node, g_type_parent (cc->instance_type));
sl@0
  1950
	  if (cc && cc->instance_type != restore_type)
sl@0
  1951
	    {
sl@0
  1952
	      closure = cc->closure;
sl@0
  1953
	      chain_type = cc->instance_type;
sl@0
  1954
	    }
sl@0
  1955
	}
sl@0
  1956
      else
sl@0
  1957
	g_warning ("%s: signal id `%u' cannot be chained from current emission stage for instance `%p'", G_STRLOC, node->signal_id, instance);
sl@0
  1958
    }
sl@0
  1959
  else
sl@0
  1960
    g_warning ("%s: no signal is currently being emitted for instance `%p'", G_STRLOC, instance);
sl@0
  1961
sl@0
  1962
  if (closure)
sl@0
  1963
    {
sl@0
  1964
      emission->chain_type = chain_type;
sl@0
  1965
      SIGNAL_UNLOCK ();
sl@0
  1966
      g_closure_invoke (closure,
sl@0
  1967
			return_value,
sl@0
  1968
			n_params + 1,
sl@0
  1969
			instance_and_params,
sl@0
  1970
			&emission->ihint);
sl@0
  1971
      SIGNAL_LOCK ();
sl@0
  1972
      emission->chain_type = restore_type;
sl@0
  1973
    }
sl@0
  1974
  SIGNAL_UNLOCK ();
sl@0
  1975
}
sl@0
  1976
sl@0
  1977
/**
sl@0
  1978
 * g_signal_chain_from_overridden_handler:
sl@0
  1979
 * @instance: the instance the signal is being emitted on.
sl@0
  1980
 * @...: parameters to be passed to the parent class closure, followed by a
sl@0
  1981
 *  location for the return value. If the return type of the signal
sl@0
  1982
 *  is #G_TYPE_NONE, the return value location can be omitted.
sl@0
  1983
 *
sl@0
  1984
 * Calls the original class closure of a signal. This function should
sl@0
  1985
 * only be called from an overridden class closure; see
sl@0
  1986
 * g_signal_override_class_closure() and
sl@0
  1987
 * g_signal_override_class_handler().
sl@0
  1988
 *
sl@0
  1989
 * Since: 2.18
sl@0
  1990
 */
sl@0
  1991
EXPORT_C void
sl@0
  1992
g_signal_chain_from_overridden_handler (gpointer instance,
sl@0
  1993
                                        ...)
sl@0
  1994
{
sl@0
  1995
  GType chain_type = 0, restore_type = 0;
sl@0
  1996
  Emission *emission = NULL;
sl@0
  1997
  GClosure *closure = NULL;
sl@0
  1998
  SignalNode *node;
sl@0
  1999
  guint n_params = 0;
sl@0
  2000
sl@0
  2001
  g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
sl@0
  2002
sl@0
  2003
  SIGNAL_LOCK ();
sl@0
  2004
  emission = emission_find_innermost (instance);
sl@0
  2005
  if (emission)
sl@0
  2006
    {
sl@0
  2007
      node = LOOKUP_SIGNAL_NODE (emission->ihint.signal_id);
sl@0
  2008
sl@0
  2009
      g_assert (node != NULL);	/* paranoid */
sl@0
  2010
sl@0
  2011
      /* we should probably do the same parameter checks as g_signal_emit() here.
sl@0
  2012
       */
sl@0
  2013
      if (emission->chain_type != G_TYPE_NONE)
sl@0
  2014
	{
sl@0
  2015
	  ClassClosure *cc = signal_find_class_closure (node, emission->chain_type);
sl@0
  2016
sl@0
  2017
	  g_assert (cc != NULL);	/* closure currently in call stack */
sl@0
  2018
sl@0
  2019
	  n_params = node->n_params;
sl@0
  2020
	  restore_type = cc->instance_type;
sl@0
  2021
	  cc = signal_find_class_closure (node, g_type_parent (cc->instance_type));
sl@0
  2022
	  if (cc && cc->instance_type != restore_type)
sl@0
  2023
	    {
sl@0
  2024
	      closure = cc->closure;
sl@0
  2025
	      chain_type = cc->instance_type;
sl@0
  2026
	    }
sl@0
  2027
	}
sl@0
  2028
      else
sl@0
  2029
	g_warning ("%s: signal id `%u' cannot be chained from current emission stage for instance `%p'", G_STRLOC, node->signal_id, instance);
sl@0
  2030
    }
sl@0
  2031
  else
sl@0
  2032
    g_warning ("%s: no signal is currently being emitted for instance `%p'", G_STRLOC, instance);
sl@0
  2033
sl@0
  2034
  if (closure)
sl@0
  2035
    {
sl@0
  2036
      GValue *instance_and_params;
sl@0
  2037
      GType signal_return_type;
sl@0
  2038
      GValue *param_values;
sl@0
  2039
      va_list var_args;
sl@0
  2040
      guint i;
sl@0
  2041
sl@0
  2042
      va_start (var_args, instance);
sl@0
  2043
sl@0
  2044
      signal_return_type = node->return_type;
sl@0
  2045
      instance_and_params = g_slice_alloc (sizeof (GValue) * (n_params + 1));
sl@0
  2046
      param_values = instance_and_params + 1;
sl@0
  2047
sl@0
  2048
      for (i = 0; i < node->n_params; i++)
sl@0
  2049
        {
sl@0
  2050
          gchar *error;
sl@0
  2051
          GType ptype = node->param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE;
sl@0
  2052
          gboolean static_scope = node->param_types[i] & G_SIGNAL_TYPE_STATIC_SCOPE;
sl@0
  2053
sl@0
  2054
          param_values[i].g_type = 0;
sl@0
  2055
          SIGNAL_UNLOCK ();
sl@0
  2056
          g_value_init (param_values + i, ptype);
sl@0
  2057
          G_VALUE_COLLECT (param_values + i,
sl@0
  2058
                           var_args,
sl@0
  2059
                           static_scope ? G_VALUE_NOCOPY_CONTENTS : 0,
sl@0
  2060
                           &error);
sl@0
  2061
          if (error)
sl@0
  2062
            {
sl@0
  2063
              g_warning ("%s: %s", G_STRLOC, error);
sl@0
  2064
              g_free (error);
sl@0
  2065
sl@0
  2066
              /* we purposely leak the value here, it might not be
sl@0
  2067
               * in a sane state if an error condition occoured
sl@0
  2068
               */
sl@0
  2069
              while (i--)
sl@0
  2070
                g_value_unset (param_values + i);
sl@0
  2071
sl@0
  2072
              g_slice_free1 (sizeof (GValue) * (n_params + 1), instance_and_params);
sl@0
  2073
              va_end (var_args);
sl@0
  2074
              return;
sl@0
  2075
            }
sl@0
  2076
          SIGNAL_LOCK ();
sl@0
  2077
        }
sl@0
  2078
sl@0
  2079
      SIGNAL_UNLOCK ();
sl@0
  2080
      instance_and_params->g_type = 0;
sl@0
  2081
      g_value_init (instance_and_params, G_TYPE_FROM_INSTANCE (instance));
sl@0
  2082
      g_value_set_instance (instance_and_params, instance);
sl@0
  2083
      SIGNAL_LOCK ();
sl@0
  2084
sl@0
  2085
      emission->chain_type = chain_type;
sl@0
  2086
      SIGNAL_UNLOCK ();
sl@0
  2087
sl@0
  2088
      if (signal_return_type == G_TYPE_NONE)
sl@0
  2089
        {
sl@0
  2090
          g_closure_invoke (closure,
sl@0
  2091
                            NULL,
sl@0
  2092
                            n_params + 1,
sl@0
  2093
                            instance_and_params,
sl@0
  2094
                            &emission->ihint);
sl@0
  2095
        }
sl@0
  2096
      else
sl@0
  2097
        {
sl@0
  2098
          GValue return_value = { 0, };
sl@0
  2099
          gchar *error = NULL;
sl@0
  2100
          GType rtype = signal_return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE;
sl@0
  2101
          gboolean static_scope = signal_return_type & G_SIGNAL_TYPE_STATIC_SCOPE;
sl@0
  2102
sl@0
  2103
          g_value_init (&return_value, rtype);
sl@0
  2104
sl@0
  2105
          g_closure_invoke (closure,
sl@0
  2106
                            &return_value,
sl@0
  2107
                            n_params + 1,
sl@0
  2108
                            instance_and_params,
sl@0
  2109
                            &emission->ihint);
sl@0
  2110
sl@0
  2111
          G_VALUE_LCOPY (&return_value,
sl@0
  2112
                         var_args,
sl@0
  2113
                         static_scope ? G_VALUE_NOCOPY_CONTENTS : 0,
sl@0
  2114
                         &error);
sl@0
  2115
          if (!error)
sl@0
  2116
            {
sl@0
  2117
              g_value_unset (&return_value);
sl@0
  2118
            }
sl@0
  2119
          else
sl@0
  2120
            {
sl@0
  2121
              g_warning ("%s: %s", G_STRLOC, error);
sl@0
  2122
              g_free (error);
sl@0
  2123
sl@0
  2124
              /* we purposely leak the value here, it might not be
sl@0
  2125
               * in a sane state if an error condition occured
sl@0
  2126
               */
sl@0
  2127
            }
sl@0
  2128
        }
sl@0
  2129
sl@0
  2130
      for (i = 0; i < n_params; i++)
sl@0
  2131
        g_value_unset (param_values + i);
sl@0
  2132
      g_value_unset (instance_and_params);
sl@0
  2133
      g_slice_free1 (sizeof (GValue) * (n_params + 1), instance_and_params);
sl@0
  2134
sl@0
  2135
      va_end (var_args);
sl@0
  2136
sl@0
  2137
      SIGNAL_LOCK ();
sl@0
  2138
      emission->chain_type = restore_type;
sl@0
  2139
    }
sl@0
  2140
  SIGNAL_UNLOCK ();
sl@0
  2141
}
sl@0
  2142
sl@0
  2143
/**
sl@0
  2144
 * g_signal_get_invocation_hint:
sl@0
  2145
 * @instance: the instance to query
sl@0
  2146
 *
sl@0
  2147
 * Returns the invocation hint of the innermost signal emission of instance.
sl@0
  2148
 *
sl@0
  2149
 * Returns: the invocation hint of the innermost signal emission.
sl@0
  2150
 */
sl@0
  2151
EXPORT_C GSignalInvocationHint*
sl@0
  2152
g_signal_get_invocation_hint (gpointer instance)
sl@0
  2153
{
sl@0
  2154
  Emission *emission = NULL;
sl@0
  2155
  
sl@0
  2156
  g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), NULL);
sl@0
  2157
sl@0
  2158
  SIGNAL_LOCK ();
sl@0
  2159
  emission = emission_find_innermost (instance);
sl@0
  2160
  SIGNAL_UNLOCK ();
sl@0
  2161
  
sl@0
  2162
  return emission ? &emission->ihint : NULL;
sl@0
  2163
}
sl@0
  2164
sl@0
  2165
/**
sl@0
  2166
 * g_signal_connect_closure_by_id:
sl@0
  2167
 * @instance: the instance to connect to.
sl@0
  2168
 * @signal_id: the id of the signal.
sl@0
  2169
 * @detail: the detail.
sl@0
  2170
 * @closure: the closure to connect.
sl@0
  2171
 * @after: whether the handler should be called before or after the
sl@0
  2172
 *  default handler of the signal.
sl@0
  2173
 *
sl@0
  2174
 * Connects a closure to a signal for a particular object.
sl@0
  2175
 *
sl@0
  2176
 * Returns: the handler id
sl@0
  2177
 */
sl@0
  2178
EXPORT_C gulong
sl@0
  2179
g_signal_connect_closure_by_id (gpointer  instance,
sl@0
  2180
				guint     signal_id,
sl@0
  2181
				GQuark    detail,
sl@0
  2182
				GClosure *closure,
sl@0
  2183
				gboolean  after)
sl@0
  2184
{
sl@0
  2185
  SignalNode *node;
sl@0
  2186
  gulong handler_seq_no = 0;
sl@0
  2187
  
sl@0
  2188
  g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
sl@0
  2189
  g_return_val_if_fail (signal_id > 0, 0);
sl@0
  2190
  g_return_val_if_fail (closure != NULL, 0);
sl@0
  2191
  
sl@0
  2192
  SIGNAL_LOCK ();
sl@0
  2193
  node = LOOKUP_SIGNAL_NODE (signal_id);
sl@0
  2194
  if (node)
sl@0
  2195
    {
sl@0
  2196
      if (detail && !(node->flags & G_SIGNAL_DETAILED))
sl@0
  2197
	g_warning ("%s: signal id `%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
sl@0
  2198
      else if (!g_type_is_a (G_TYPE_FROM_INSTANCE (instance), node->itype))
sl@0
  2199
	g_warning ("%s: signal id `%u' is invalid for instance `%p'", G_STRLOC, signal_id, instance);
sl@0
  2200
      else
sl@0
  2201
	{
sl@0
  2202
	  Handler *handler = handler_new (after);
sl@0
  2203
	  
sl@0
  2204
	  handler_seq_no = handler->sequential_number;
sl@0
  2205
	  handler->detail = detail;
sl@0
  2206
	  handler->closure = g_closure_ref (closure);
sl@0
  2207
	  g_closure_sink (closure);
sl@0
  2208
	  handler_insert (signal_id, instance, handler);
sl@0
  2209
	  if (node->c_marshaller && G_CLOSURE_NEEDS_MARSHAL (closure))
sl@0
  2210
	    g_closure_set_marshal (closure, node->c_marshaller);
sl@0
  2211
	}
sl@0
  2212
    }
sl@0
  2213
  else
sl@0
  2214
    g_warning ("%s: signal id `%u' is invalid for instance `%p'", G_STRLOC, signal_id, instance);
sl@0
  2215
  SIGNAL_UNLOCK ();
sl@0
  2216
  
sl@0
  2217
  return handler_seq_no;
sl@0
  2218
}
sl@0
  2219
sl@0
  2220
/**
sl@0
  2221
 * g_signal_connect_closure:
sl@0
  2222
 * @instance: the instance to connect to.
sl@0
  2223
 * @detailed_signal: a string of the form "signal-name::detail".
sl@0
  2224
 * @closure: the closure to connect.
sl@0
  2225
 * @after: whether the handler should be called before or after the
sl@0
  2226
 *  default handler of the signal.
sl@0
  2227
 *
sl@0
  2228
 * Connects a closure to a signal for a particular object.
sl@0
  2229
 *
sl@0
  2230
 * Returns: the handler id
sl@0
  2231
 */
sl@0
  2232
EXPORT_C gulong
sl@0
  2233
g_signal_connect_closure (gpointer     instance,
sl@0
  2234
			  const gchar *detailed_signal,
sl@0
  2235
			  GClosure    *closure,
sl@0
  2236
			  gboolean     after)
sl@0
  2237
{
sl@0
  2238
  guint signal_id;
sl@0
  2239
  gulong handler_seq_no = 0;
sl@0
  2240
  GQuark detail = 0;
sl@0
  2241
  GType itype;
sl@0
  2242
sl@0
  2243
  g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
sl@0
  2244
  g_return_val_if_fail (detailed_signal != NULL, 0);
sl@0
  2245
  g_return_val_if_fail (closure != NULL, 0);
sl@0
  2246
sl@0
  2247
  SIGNAL_LOCK ();
sl@0
  2248
  itype = G_TYPE_FROM_INSTANCE (instance);
sl@0
  2249
  signal_id = signal_parse_name (detailed_signal, itype, &detail, TRUE);
sl@0
  2250
  if (signal_id)
sl@0
  2251
    {
sl@0
  2252
      SignalNode *node = LOOKUP_SIGNAL_NODE (signal_id);
sl@0
  2253
sl@0
  2254
      if (detail && !(node->flags & G_SIGNAL_DETAILED))
sl@0
  2255
	g_warning ("%s: signal `%s' does not support details", G_STRLOC, detailed_signal);
sl@0
  2256
      else if (!g_type_is_a (itype, node->itype))
sl@0
  2257
	g_warning ("%s: signal `%s' is invalid for instance `%p'", G_STRLOC, detailed_signal, instance);
sl@0
  2258
      else
sl@0
  2259
	{
sl@0
  2260
	  Handler *handler = handler_new (after);
sl@0
  2261
sl@0
  2262
	  handler_seq_no = handler->sequential_number;
sl@0
  2263
	  handler->detail = detail;
sl@0
  2264
	  handler->closure = g_closure_ref (closure);
sl@0
  2265
	  g_closure_sink (closure);
sl@0
  2266
	  handler_insert (signal_id, instance, handler);
sl@0
  2267
	  if (node->c_marshaller && G_CLOSURE_NEEDS_MARSHAL (handler->closure))
sl@0
  2268
	    g_closure_set_marshal (handler->closure, node->c_marshaller);
sl@0
  2269
	}
sl@0
  2270
    }
sl@0
  2271
  else
sl@0
  2272
    g_warning ("%s: signal `%s' is invalid for instance `%p'", G_STRLOC, detailed_signal, instance);
sl@0
  2273
  SIGNAL_UNLOCK ();
sl@0
  2274
sl@0
  2275
  return handler_seq_no;
sl@0
  2276
}
sl@0
  2277
sl@0
  2278
/**
sl@0
  2279
 * g_signal_connect_data:
sl@0
  2280
 * @instance: the instance to connect to.
sl@0
  2281
 * @detailed_signal: a string of the form "signal-name::detail".
sl@0
  2282
 * @c_handler: the #GCallback to connect.
sl@0
  2283
 * @data: data to pass to @c_handler calls.
sl@0
  2284
 * @destroy_data: a #GClosureNotify for @data.
sl@0
  2285
 * @connect_flags: a combination of #GConnectFlags.
sl@0
  2286
 *
sl@0
  2287
 * Connects a #GCallback function to a signal for a particular object. Similar
sl@0
  2288
 * to g_signal_connect(), but allows to provide a #GClosureNotify for the data
sl@0
  2289
 * which will be called when the signal handler is disconnected and no longer
sl@0
  2290
 * used. Specify @connect_flags if you need <literal>..._after()</literal> or
sl@0
  2291
 * <literal>..._swapped()</literal> variants of this function.
sl@0
  2292
 *
sl@0
  2293
 * Returns: the handler id
sl@0
  2294
 */
sl@0
  2295
EXPORT_C gulong
sl@0
  2296
g_signal_connect_data (gpointer       instance,
sl@0
  2297
		       const gchar   *detailed_signal,
sl@0
  2298
		       GCallback      c_handler,
sl@0
  2299
		       gpointer       data,
sl@0
  2300
		       GClosureNotify destroy_data,
sl@0
  2301
		       GConnectFlags  connect_flags)
sl@0
  2302
{
sl@0
  2303
  guint signal_id;
sl@0
  2304
  gulong handler_seq_no = 0;
sl@0
  2305
  GQuark detail = 0;
sl@0
  2306
  GType itype;
sl@0
  2307
  gboolean swapped, after;
sl@0
  2308
  
sl@0
  2309
  g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
sl@0
  2310
  g_return_val_if_fail (detailed_signal != NULL, 0);
sl@0
  2311
  g_return_val_if_fail (c_handler != NULL, 0);
sl@0
  2312
sl@0
  2313
  swapped = (connect_flags & G_CONNECT_SWAPPED) != FALSE;
sl@0
  2314
  after = (connect_flags & G_CONNECT_AFTER) != FALSE;
sl@0
  2315
sl@0
  2316
  SIGNAL_LOCK ();
sl@0
  2317
  itype = G_TYPE_FROM_INSTANCE (instance);
sl@0
  2318
  signal_id = signal_parse_name (detailed_signal, itype, &detail, TRUE);
sl@0
  2319
  if (signal_id)
sl@0
  2320
    {
sl@0
  2321
      SignalNode *node = LOOKUP_SIGNAL_NODE (signal_id);
sl@0
  2322
sl@0
  2323
      if (detail && !(node->flags & G_SIGNAL_DETAILED))
sl@0
  2324
	g_warning ("%s: signal `%s' does not support details", G_STRLOC, detailed_signal);
sl@0
  2325
      else if (!g_type_is_a (itype, node->itype))
sl@0
  2326
	g_warning ("%s: signal `%s' is invalid for instance `%p'", G_STRLOC, detailed_signal, instance);
sl@0
  2327
      else
sl@0
  2328
	{
sl@0
  2329
	  Handler *handler = handler_new (after);
sl@0
  2330
sl@0
  2331
	  handler_seq_no = handler->sequential_number;
sl@0
  2332
	  handler->detail = detail;
sl@0
  2333
	  handler->closure = g_closure_ref ((swapped ? g_cclosure_new_swap : g_cclosure_new) (c_handler, data, destroy_data));
sl@0
  2334
	  g_closure_sink (handler->closure);
sl@0
  2335
	  handler_insert (signal_id, instance, handler);
sl@0
  2336
	  if (node->c_marshaller && G_CLOSURE_NEEDS_MARSHAL (handler->closure))
sl@0
  2337
	    g_closure_set_marshal (handler->closure, node->c_marshaller);
sl@0
  2338
	}
sl@0
  2339
    }
sl@0
  2340
  else
sl@0
  2341
    g_warning ("%s: signal `%s' is invalid for instance `%p'", G_STRLOC, detailed_signal, instance);
sl@0
  2342
  SIGNAL_UNLOCK ();
sl@0
  2343
sl@0
  2344
  return handler_seq_no;
sl@0
  2345
}
sl@0
  2346
sl@0
  2347
/**
sl@0
  2348
 * g_signal_handler_block:
sl@0
  2349
 * @instance: The instance to block the signal handler of.
sl@0
  2350
 * @handler_id: Handler id of the handler to be blocked.
sl@0
  2351
 *
sl@0
  2352
 * Blocks a handler of an instance so it will not be called during any
sl@0
  2353
 * signal emissions unless it is unblocked again. Thus "blocking" a
sl@0
  2354
 * signal handler means to temporarily deactive it, a signal handler
sl@0
  2355
 * has to be unblocked exactly the same amount of times it has been
sl@0
  2356
 * blocked before to become active again.
sl@0
  2357
 *
sl@0
  2358
 * The @handler_id has to be a valid signal handler id, connected to a
sl@0
  2359
 * signal of @instance.
sl@0
  2360
 */
sl@0
  2361
EXPORT_C void
sl@0
  2362
g_signal_handler_block (gpointer instance,
sl@0
  2363
                        gulong   handler_id)
sl@0
  2364
{
sl@0
  2365
  Handler *handler;
sl@0
  2366
  
sl@0
  2367
  g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
sl@0
  2368
  g_return_if_fail (handler_id > 0);
sl@0
  2369
  
sl@0
  2370
  SIGNAL_LOCK ();
sl@0
  2371
  handler = handler_lookup (instance, handler_id, NULL);
sl@0
  2372
  if (handler)
sl@0
  2373
    {
sl@0
  2374
#ifndef G_DISABLE_CHECKS
sl@0
  2375
      if (handler->block_count >= HANDLER_MAX_BLOCK_COUNT - 1)
sl@0
  2376
        g_error (G_STRLOC ": handler block_count overflow, %s", REPORT_BUG);
sl@0
  2377
#endif
sl@0
  2378
      handler->block_count += 1;
sl@0
  2379
    }
sl@0
  2380
  else
sl@0
  2381
    g_warning ("%s: instance `%p' has no handler with id `%lu'", G_STRLOC, instance, handler_id);
sl@0
  2382
  SIGNAL_UNLOCK ();
sl@0
  2383
}
sl@0
  2384
sl@0
  2385
/**
sl@0
  2386
 * g_signal_handler_unblock:
sl@0
  2387
 * @instance: The instance to unblock the signal handler of.
sl@0
  2388
 * @handler_id: Handler id of the handler to be unblocked.
sl@0
  2389
 *
sl@0
  2390
 * Undoes the effect of a previous g_signal_handler_block() call.  A
sl@0
  2391
 * blocked handler is skipped during signal emissions and will not be
sl@0
  2392
 * invoked, unblocking it (for exactly the amount of times it has been
sl@0
  2393
 * blocked before) reverts its "blocked" state, so the handler will be
sl@0
  2394
 * recognized by the signal system and is called upon future or
sl@0
  2395
 * currently ongoing signal emissions (since the order in which
sl@0
  2396
 * handlers are called during signal emissions is deterministic,
sl@0
  2397
 * whether the unblocked handler in question is called as part of a
sl@0
  2398
 * currently ongoing emission depends on how far that emission has
sl@0
  2399
 * proceeded yet).
sl@0
  2400
 *
sl@0
  2401
 * The @handler_id has to be a valid id of a signal handler that is
sl@0
  2402
 * connected to a signal of @instance and is currently blocked.
sl@0
  2403
 */
sl@0
  2404
EXPORT_C void
sl@0
  2405
g_signal_handler_unblock (gpointer instance,
sl@0
  2406
                          gulong   handler_id)
sl@0
  2407
{
sl@0
  2408
  Handler *handler;
sl@0
  2409
  
sl@0
  2410
  g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
sl@0
  2411
  g_return_if_fail (handler_id > 0);
sl@0
  2412
  
sl@0
  2413
  SIGNAL_LOCK ();
sl@0
  2414
  handler = handler_lookup (instance, handler_id, NULL);
sl@0
  2415
  if (handler)
sl@0
  2416
    {
sl@0
  2417
      if (handler->block_count)
sl@0
  2418
        handler->block_count -= 1;
sl@0
  2419
      else
sl@0
  2420
        g_warning (G_STRLOC ": handler `%lu' of instance `%p' is not blocked", handler_id, instance);
sl@0
  2421
    }
sl@0
  2422
  else
sl@0
  2423
    g_warning ("%s: instance `%p' has no handler with id `%lu'", G_STRLOC, instance, handler_id);
sl@0
  2424
  SIGNAL_UNLOCK ();
sl@0
  2425
}
sl@0
  2426
sl@0
  2427
/**
sl@0
  2428
 * g_signal_handler_disconnect:
sl@0
  2429
 * @instance: The instance to remove the signal handler from.
sl@0
  2430
 * @handler_id: Handler id of the handler to be disconnected.
sl@0
  2431
 *
sl@0
  2432
 * Disconnects a handler from an instance so it will not be called during
sl@0
  2433
 * any future or currently ongoing emissions of the signal it has been
sl@0
  2434
 * connected to. The @handler_id becomes invalid and may be reused.
sl@0
  2435
 *
sl@0
  2436
 * The @handler_id has to be a valid signal handler id, connected to a
sl@0
  2437
 * signal of @instance.
sl@0
  2438
 */
sl@0
  2439
EXPORT_C void
sl@0
  2440
g_signal_handler_disconnect (gpointer instance,
sl@0
  2441
                             gulong   handler_id)
sl@0
  2442
{
sl@0
  2443
  Handler *handler;
sl@0
  2444
  guint signal_id;
sl@0
  2445
  
sl@0
  2446
  g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
sl@0
  2447
  g_return_if_fail (handler_id > 0);
sl@0
  2448
  
sl@0
  2449
  SIGNAL_LOCK ();
sl@0
  2450
  handler = handler_lookup (instance, handler_id, &signal_id);
sl@0
  2451
  if (handler)
sl@0
  2452
    {
sl@0
  2453
      handler->sequential_number = 0;
sl@0
  2454
      handler->block_count = 1;
sl@0
  2455
      handler_unref_R (signal_id, instance, handler);
sl@0
  2456
    }
sl@0
  2457
  else
sl@0
  2458
    g_warning ("%s: instance `%p' has no handler with id `%lu'", G_STRLOC, instance, handler_id);
sl@0
  2459
  SIGNAL_UNLOCK ();
sl@0
  2460
}
sl@0
  2461
sl@0
  2462
/**
sl@0
  2463
 * g_signal_handler_is_connected:
sl@0
  2464
 * @instance: The instance where a signal handler is sought.
sl@0
  2465
 * @handler_id: the handler id.
sl@0
  2466
 *
sl@0
  2467
 * Returns whether @handler_id is the id of a handler connected to @instance.
sl@0
  2468
 *
sl@0
  2469
 * Returns: whether @handler_id identifies a handler connected to @instance.
sl@0
  2470
 */
sl@0
  2471
EXPORT_C gboolean
sl@0
  2472
g_signal_handler_is_connected (gpointer instance,
sl@0
  2473
			       gulong   handler_id)
sl@0
  2474
{
sl@0
  2475
  Handler *handler;
sl@0
  2476
  gboolean connected;
sl@0
  2477
sl@0
  2478
  g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), FALSE);
sl@0
  2479
sl@0
  2480
  SIGNAL_LOCK ();
sl@0
  2481
  handler = handler_lookup (instance, handler_id, NULL);
sl@0
  2482
  connected = handler != NULL;
sl@0
  2483
  SIGNAL_UNLOCK ();
sl@0
  2484
sl@0
  2485
  return connected;
sl@0
  2486
}
sl@0
  2487
sl@0
  2488
EXPORT_C void
sl@0
  2489
g_signal_handlers_destroy (gpointer instance)
sl@0
  2490
{
sl@0
  2491
  GBSearchArray *hlbsa;
sl@0
  2492
  
sl@0
  2493
  g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
sl@0
  2494
  
sl@0
  2495
  SIGNAL_LOCK ();
sl@0
  2496
  hlbsa = g_hash_table_lookup (g_handler_list_bsa_ht, instance);
sl@0
  2497
  if (hlbsa)
sl@0
  2498
    {
sl@0
  2499
      guint i;
sl@0
  2500
      
sl@0
  2501
      /* reentrancy caution, delete instance trace first */
sl@0
  2502
      g_hash_table_remove (g_handler_list_bsa_ht, instance);
sl@0
  2503
      
sl@0
  2504
      for (i = 0; i < hlbsa->n_nodes; i++)
sl@0
  2505
        {
sl@0
  2506
          HandlerList *hlist = g_bsearch_array_get_nth (hlbsa, &g_signal_hlbsa_bconfig, i);
sl@0
  2507
          Handler *handler = hlist->handlers;
sl@0
  2508
	  
sl@0
  2509
          while (handler)
sl@0
  2510
            {
sl@0
  2511
              Handler *tmp = handler;
sl@0
  2512
	      
sl@0
  2513
              handler = tmp->next;
sl@0
  2514
              tmp->block_count = 1;
sl@0
  2515
              /* cruel unlink, this works because _all_ handlers vanish */
sl@0
  2516
              tmp->next = NULL;
sl@0
  2517
              tmp->prev = tmp;
sl@0
  2518
              if (tmp->sequential_number)
sl@0
  2519
		{
sl@0
  2520
		  tmp->sequential_number = 0;
sl@0
  2521
		  handler_unref_R (0, NULL, tmp);
sl@0
  2522
		}
sl@0
  2523
            }
sl@0
  2524
        }
sl@0
  2525
      g_bsearch_array_free (hlbsa, &g_signal_hlbsa_bconfig);
sl@0
  2526
    }
sl@0
  2527
  SIGNAL_UNLOCK ();
sl@0
  2528
}
sl@0
  2529
sl@0
  2530
/**
sl@0
  2531
 * g_signal_handler_find:
sl@0
  2532
 * @instance: The instance owning the signal handler to be found.
sl@0
  2533
 * @mask: Mask indicating which of @signal_id, @detail, @closure, @func
sl@0
  2534
 *  and/or @data the handler has to match.
sl@0
  2535
 * @signal_id: Signal the handler has to be connected to.
sl@0
  2536
 * @detail: Signal detail the handler has to be connected to.
sl@0
  2537
 * @closure: The closure the handler will invoke.
sl@0
  2538
 * @func: The C closure callback of the handler (useless for non-C closures).
sl@0
  2539
 * @data: The closure data of the handler's closure.
sl@0
  2540
 *
sl@0
  2541
 * Finds the first signal handler that matches certain selection criteria.
sl@0
  2542
 * The criteria mask is passed as an OR-ed combination of #GSignalMatchType
sl@0
  2543
 * flags, and the criteria values are passed as arguments.
sl@0
  2544
 * The match @mask has to be non-0 for successful matches.
sl@0
  2545
 * If no handler was found, 0 is returned.
sl@0
  2546
 *
sl@0
  2547
 * Returns: A valid non-0 signal handler id for a successful match.
sl@0
  2548
 */
sl@0
  2549
EXPORT_C gulong
sl@0
  2550
g_signal_handler_find (gpointer         instance,
sl@0
  2551
                       GSignalMatchType mask,
sl@0
  2552
                       guint            signal_id,
sl@0
  2553
		       GQuark		detail,
sl@0
  2554
                       GClosure        *closure,
sl@0
  2555
                       gpointer         func,
sl@0
  2556
                       gpointer         data)
sl@0
  2557
{
sl@0
  2558
  gulong handler_seq_no = 0;
sl@0
  2559
  
sl@0
  2560
  g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
sl@0
  2561
  g_return_val_if_fail ((mask & ~G_SIGNAL_MATCH_MASK) == 0, 0);
sl@0
  2562
  
sl@0
  2563
  if (mask & G_SIGNAL_MATCH_MASK)
sl@0
  2564
    {
sl@0
  2565
      HandlerMatch *mlist;
sl@0
  2566
      
sl@0
  2567
      SIGNAL_LOCK ();
sl@0
  2568
      mlist = handlers_find (instance, mask, signal_id, detail, closure, func, data, TRUE);
sl@0
  2569
      if (mlist)
sl@0
  2570
	{
sl@0
  2571
	  handler_seq_no = mlist->handler->sequential_number;
sl@0
  2572
	  handler_match_free1_R (mlist, instance);
sl@0
  2573
	}
sl@0
  2574
      SIGNAL_UNLOCK ();
sl@0
  2575
    }
sl@0
  2576
  
sl@0
  2577
  return handler_seq_no;
sl@0
  2578
}
sl@0
  2579
sl@0
  2580
static guint
sl@0
  2581
signal_handlers_foreach_matched_R (gpointer         instance,
sl@0
  2582
				   GSignalMatchType mask,
sl@0
  2583
				   guint            signal_id,
sl@0
  2584
				   GQuark           detail,
sl@0
  2585
				   GClosure        *closure,
sl@0
  2586
				   gpointer         func,
sl@0
  2587
				   gpointer         data,
sl@0
  2588
				   void		  (*callback) (gpointer instance,
sl@0
  2589
							       gulong   handler_seq_no))
sl@0
  2590
{
sl@0
  2591
  HandlerMatch *mlist;
sl@0
  2592
  guint n_handlers = 0;
sl@0
  2593
  
sl@0
  2594
  mlist = handlers_find (instance, mask, signal_id, detail, closure, func, data, FALSE);
sl@0
  2595
  while (mlist)
sl@0
  2596
    {
sl@0
  2597
      n_handlers++;
sl@0
  2598
      if (mlist->handler->sequential_number)
sl@0
  2599
	{
sl@0
  2600
	  SIGNAL_UNLOCK ();
sl@0
  2601
	  callback (instance, mlist->handler->sequential_number);
sl@0
  2602
	  SIGNAL_LOCK ();
sl@0
  2603
	}
sl@0
  2604
      mlist = handler_match_free1_R (mlist, instance);
sl@0
  2605
    }
sl@0
  2606
  
sl@0
  2607
  return n_handlers;
sl@0
  2608
}
sl@0
  2609
sl@0
  2610
/**
sl@0
  2611
 * g_signal_handlers_block_matched:
sl@0
  2612
 * @instance: The instance to block handlers from.
sl@0
  2613
 * @mask: Mask indicating which of @signal_id, @detail, @closure, @func
sl@0
  2614
 *  and/or @data the handlers have to match.
sl@0
  2615
 * @signal_id: Signal the handlers have to be connected to.
sl@0
  2616
 * @detail: Signal detail the handlers have to be connected to.
sl@0
  2617
 * @closure: The closure the handlers will invoke.
sl@0
  2618
 * @func: The C closure callback of the handlers (useless for non-C closures).
sl@0
  2619
 * @data: The closure data of the handlers' closures.
sl@0
  2620
 *
sl@0
  2621
 * Blocks all handlers on an instance that match a certain selection criteria.
sl@0
  2622
 * The criteria mask is passed as an OR-ed combination of #GSignalMatchType
sl@0
  2623
 * flags, and the criteria values are passed as arguments.
sl@0
  2624
 * Passing at least one of the %G_SIGNAL_MATCH_CLOSURE, %G_SIGNAL_MATCH_FUNC
sl@0
  2625
 * or %G_SIGNAL_MATCH_DATA match flags is required for successful matches.
sl@0
  2626
 * If no handlers were found, 0 is returned, the number of blocked handlers
sl@0
  2627
 * otherwise.
sl@0
  2628
 *
sl@0
  2629
 * Returns: The number of handlers that matched.
sl@0
  2630
 */
sl@0
  2631
EXPORT_C guint
sl@0
  2632
g_signal_handlers_block_matched (gpointer         instance,
sl@0
  2633
				 GSignalMatchType mask,
sl@0
  2634
				 guint            signal_id,
sl@0
  2635
				 GQuark           detail,
sl@0
  2636
				 GClosure        *closure,
sl@0
  2637
				 gpointer         func,
sl@0
  2638
				 gpointer         data)
sl@0
  2639
{
sl@0
  2640
  guint n_handlers = 0;
sl@0
  2641
  
sl@0
  2642
  g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
sl@0
  2643
  g_return_val_if_fail ((mask & ~G_SIGNAL_MATCH_MASK) == 0, 0);
sl@0
  2644
  
sl@0
  2645
  if (mask & (G_SIGNAL_MATCH_CLOSURE | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA))
sl@0
  2646
    {
sl@0
  2647
      SIGNAL_LOCK ();
sl@0
  2648
      n_handlers = signal_handlers_foreach_matched_R (instance, mask, signal_id, detail,
sl@0
  2649
						      closure, func, data,
sl@0
  2650
						      g_signal_handler_block);
sl@0
  2651
      SIGNAL_UNLOCK ();
sl@0
  2652
    }
sl@0
  2653
  
sl@0
  2654
  return n_handlers;
sl@0
  2655
}
sl@0
  2656
sl@0
  2657
/**
sl@0
  2658
 * g_signal_handlers_unblock_matched:
sl@0
  2659
 * @instance: The instance to unblock handlers from.
sl@0
  2660
 * @mask: Mask indicating which of @signal_id, @detail, @closure, @func
sl@0
  2661
 *  and/or @data the handlers have to match.
sl@0
  2662
 * @signal_id: Signal the handlers have to be connected to.
sl@0
  2663
 * @detail: Signal detail the handlers have to be connected to.
sl@0
  2664
 * @closure: The closure the handlers will invoke.
sl@0
  2665
 * @func: The C closure callback of the handlers (useless for non-C closures).
sl@0
  2666
 * @data: The closure data of the handlers' closures.
sl@0
  2667
 *
sl@0
  2668
 * Unblocks all handlers on an instance that match a certain selection
sl@0
  2669
 * criteria. The criteria mask is passed as an OR-ed combination of
sl@0
  2670
 * #GSignalMatchType flags, and the criteria values are passed as arguments.
sl@0
  2671
 * Passing at least one of the %G_SIGNAL_MATCH_CLOSURE, %G_SIGNAL_MATCH_FUNC
sl@0
  2672
 * or %G_SIGNAL_MATCH_DATA match flags is required for successful matches.
sl@0
  2673
 * If no handlers were found, 0 is returned, the number of unblocked handlers
sl@0
  2674
 * otherwise. The match criteria should not apply to any handlers that are
sl@0
  2675
 * not currently blocked.
sl@0
  2676
 *
sl@0
  2677
 * Returns: The number of handlers that matched.
sl@0
  2678
 */
sl@0
  2679
EXPORT_C guint
sl@0
  2680
g_signal_handlers_unblock_matched (gpointer         instance,
sl@0
  2681
				   GSignalMatchType mask,
sl@0
  2682
				   guint            signal_id,
sl@0
  2683
				   GQuark           detail,
sl@0
  2684
				   GClosure        *closure,
sl@0
  2685
				   gpointer         func,
sl@0
  2686
				   gpointer         data)
sl@0
  2687
{
sl@0
  2688
  guint n_handlers = 0;
sl@0
  2689
  
sl@0
  2690
  g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
sl@0
  2691
  g_return_val_if_fail ((mask & ~G_SIGNAL_MATCH_MASK) == 0, 0);
sl@0
  2692
  
sl@0
  2693
  if (mask & (G_SIGNAL_MATCH_CLOSURE | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA))
sl@0
  2694
    {
sl@0
  2695
      SIGNAL_LOCK ();
sl@0
  2696
      n_handlers = signal_handlers_foreach_matched_R (instance, mask, signal_id, detail,
sl@0
  2697
						      closure, func, data,
sl@0
  2698
						      g_signal_handler_unblock);
sl@0
  2699
      SIGNAL_UNLOCK ();
sl@0
  2700
    }
sl@0
  2701
  
sl@0
  2702
  return n_handlers;
sl@0
  2703
}
sl@0
  2704
sl@0
  2705
/**
sl@0
  2706
 * g_signal_handlers_disconnect_matched:
sl@0
  2707
 * @instance: The instance to remove handlers from.
sl@0
  2708
 * @mask: Mask indicating which of @signal_id, @detail, @closure, @func
sl@0
  2709
 *  and/or @data the handlers have to match.
sl@0
  2710
 * @signal_id: Signal the handlers have to be connected to.
sl@0
  2711
 * @detail: Signal detail the handlers have to be connected to.
sl@0
  2712
 * @closure: The closure the handlers will invoke.
sl@0
  2713
 * @func: The C closure callback of the handlers (useless for non-C closures).
sl@0
  2714
 * @data: The closure data of the handlers' closures.
sl@0
  2715
 *
sl@0
  2716
 * Disconnects all handlers on an instance that match a certain
sl@0
  2717
 * selection criteria. The criteria mask is passed as an OR-ed
sl@0
  2718
 * combination of #GSignalMatchType flags, and the criteria values are
sl@0
  2719
 * passed as arguments.  Passing at least one of the
sl@0
  2720
 * %G_SIGNAL_MATCH_CLOSURE, %G_SIGNAL_MATCH_FUNC or
sl@0
  2721
 * %G_SIGNAL_MATCH_DATA match flags is required for successful
sl@0
  2722
 * matches.  If no handlers were found, 0 is returned, the number of
sl@0
  2723
 * disconnected handlers otherwise.
sl@0
  2724
 *
sl@0
  2725
 * Returns: The number of handlers that matched.
sl@0
  2726
 */
sl@0
  2727
EXPORT_C guint
sl@0
  2728
g_signal_handlers_disconnect_matched (gpointer         instance,
sl@0
  2729
				      GSignalMatchType mask,
sl@0
  2730
				      guint            signal_id,
sl@0
  2731
				      GQuark           detail,
sl@0
  2732
				      GClosure        *closure,
sl@0
  2733
				      gpointer         func,
sl@0
  2734
				      gpointer         data)
sl@0
  2735
{
sl@0
  2736
  guint n_handlers = 0;
sl@0
  2737
  
sl@0
  2738
  g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
sl@0
  2739
  g_return_val_if_fail ((mask & ~G_SIGNAL_MATCH_MASK) == 0, 0);
sl@0
  2740
  
sl@0
  2741
  if (mask & (G_SIGNAL_MATCH_CLOSURE | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA))
sl@0
  2742
    {
sl@0
  2743
      SIGNAL_LOCK ();
sl@0
  2744
      n_handlers = signal_handlers_foreach_matched_R (instance, mask, signal_id, detail,
sl@0
  2745
						      closure, func, data,
sl@0
  2746
						      g_signal_handler_disconnect);
sl@0
  2747
      SIGNAL_UNLOCK ();
sl@0
  2748
    }
sl@0
  2749
  
sl@0
  2750
  return n_handlers;
sl@0
  2751
}
sl@0
  2752
sl@0
  2753
/**
sl@0
  2754
 * g_signal_has_handler_pending:
sl@0
  2755
 * @instance: the object whose signal handlers are sought.
sl@0
  2756
 * @signal_id: the signal id.
sl@0
  2757
 * @detail: the detail.
sl@0
  2758
 * @may_be_blocked: whether blocked handlers should count as match.
sl@0
  2759
 *
sl@0
  2760
 * Returns whether there are any handlers connected to @instance for the
sl@0
  2761
 * given signal id and detail.
sl@0
  2762
 *
sl@0
  2763
 * One example of when you might use this is when the arguments to the
sl@0
  2764
 * signal are difficult to compute. A class implementor may opt to not
sl@0
  2765
 * emit the signal if no one is attached anyway, thus saving the cost
sl@0
  2766
 * of building the arguments.
sl@0
  2767
 *
sl@0
  2768
 * Returns: %TRUE if a handler is connected to the signal, %FALSE
sl@0
  2769
 *          otherwise.
sl@0
  2770
 */
sl@0
  2771
EXPORT_C gboolean
sl@0
  2772
g_signal_has_handler_pending (gpointer instance,
sl@0
  2773
			      guint    signal_id,
sl@0
  2774
			      GQuark   detail,
sl@0
  2775
			      gboolean may_be_blocked)
sl@0
  2776
{
sl@0
  2777
  HandlerMatch *mlist;
sl@0
  2778
  gboolean has_pending;
sl@0
  2779
  
sl@0
  2780
  g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), FALSE);
sl@0
  2781
  g_return_val_if_fail (signal_id > 0, FALSE);
sl@0
  2782
  
sl@0
  2783
  SIGNAL_LOCK ();
sl@0
  2784
  if (detail)
sl@0
  2785
    {
sl@0
  2786
      SignalNode *node = LOOKUP_SIGNAL_NODE (signal_id);
sl@0
  2787
      
sl@0
  2788
      if (!(node->flags & G_SIGNAL_DETAILED))
sl@0
  2789
	{
sl@0
  2790
	  g_warning ("%s: signal id `%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
sl@0
  2791
	  SIGNAL_UNLOCK ();
sl@0
  2792
	  return FALSE;
sl@0
  2793
	}
sl@0
  2794
    }
sl@0
  2795
  mlist = handlers_find (instance,
sl@0
  2796
			 (G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | (may_be_blocked ? 0 : G_SIGNAL_MATCH_UNBLOCKED)),
sl@0
  2797
			 signal_id, detail, NULL, NULL, NULL, TRUE);
sl@0
  2798
  if (mlist)
sl@0
  2799
    {
sl@0
  2800
      has_pending = TRUE;
sl@0
  2801
      handler_match_free1_R (mlist, instance);
sl@0
  2802
    }
sl@0
  2803
  else
sl@0
  2804
    has_pending = FALSE;
sl@0
  2805
  SIGNAL_UNLOCK ();
sl@0
  2806
  
sl@0
  2807
  return has_pending;
sl@0
  2808
}
sl@0
  2809
sl@0
  2810
static inline gboolean
sl@0
  2811
signal_check_skip_emission (SignalNode *node,
sl@0
  2812
			    gpointer    instance,
sl@0
  2813
			    GQuark      detail)
sl@0
  2814
{
sl@0
  2815
  HandlerList *hlist;
sl@0
  2816
sl@0
  2817
  /* are we able to check for NULL class handlers? */
sl@0
  2818
  if (!node->test_class_offset)
sl@0
  2819
    return FALSE;
sl@0
  2820
sl@0
  2821
  /* are there emission hooks pending? */
sl@0
  2822
  if (node->emission_hooks && node->emission_hooks->hooks)
sl@0
  2823
    return FALSE;
sl@0
  2824
sl@0
  2825
  /* is there a non-NULL class handler? */
sl@0
  2826
  if (node->test_class_offset != TEST_CLASS_MAGIC)
sl@0
  2827
    {
sl@0
  2828
      GTypeClass *class = G_TYPE_INSTANCE_GET_CLASS (instance, G_TYPE_FROM_INSTANCE (instance), GTypeClass);
sl@0
  2829
sl@0
  2830
      if (G_STRUCT_MEMBER (gpointer, class, node->test_class_offset))
sl@0
  2831
	return FALSE;
sl@0
  2832
    }
sl@0
  2833
sl@0
  2834
  /* are signals being debugged? */
sl@0
  2835
#ifdef  G_ENABLE_DEBUG
sl@0
  2836
  IF_DEBUG (SIGNALS, g_trace_instance_signals || g_trap_instance_signals)
sl@0
  2837
    return FALSE;
sl@0
  2838
#endif /* G_ENABLE_DEBUG */
sl@0
  2839
sl@0
  2840
  /* is this a no-recurse signal already in emission? */
sl@0
  2841
  if (node->flags & G_SIGNAL_NO_RECURSE &&
sl@0
  2842
      emission_find (g_restart_emissions, node->signal_id, detail, instance))
sl@0
  2843
    return FALSE;
sl@0
  2844
sl@0
  2845
  /* do we have pending handlers? */
sl@0
  2846
  hlist = handler_list_lookup (node->signal_id, instance);
sl@0
  2847
  if (hlist && hlist->handlers)
sl@0
  2848
    return FALSE;
sl@0
  2849
sl@0
  2850
  /* none of the above, no emission required */
sl@0
  2851
  return TRUE;
sl@0
  2852
}
sl@0
  2853
sl@0
  2854
/**
sl@0
  2855
 * g_signal_emitv:
sl@0
  2856
 * @instance_and_params: argument list for the signal emission. The first
sl@0
  2857
 *  element in the array is a #GValue for the instance the signal is
sl@0
  2858
 *  being emitted on. The rest are any arguments to be passed to the
sl@0
  2859
 *  signal.
sl@0
  2860
 * @signal_id: the signal id
sl@0
  2861
 * @detail: the detail
sl@0
  2862
 * @return_value: Location to store the return value of the signal emission.
sl@0
  2863
 *
sl@0
  2864
 * Emits a signal.
sl@0
  2865
 *
sl@0
  2866
 * Note that g_signal_emitv() doesn't change @return_value if no handlers are
sl@0
  2867
 * connected, in contrast to g_signal_emit() and g_signal_emit_valist().
sl@0
  2868
 */
sl@0
  2869
EXPORT_C void
sl@0
  2870
g_signal_emitv (const GValue *instance_and_params,
sl@0
  2871
		guint         signal_id,
sl@0
  2872
		GQuark	      detail,
sl@0
  2873
		GValue       *return_value)
sl@0
  2874
{
sl@0
  2875
  gpointer instance;
sl@0
  2876
  SignalNode *node;
sl@0
  2877
#ifdef G_ENABLE_DEBUG
sl@0
  2878
  const GValue *param_values;
sl@0
  2879
  guint i;
sl@0
  2880
#endif
sl@0
  2881
  
sl@0
  2882
  g_return_if_fail (instance_and_params != NULL);
sl@0
  2883
  instance = g_value_peek_pointer (instance_and_params);
sl@0
  2884
  g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
sl@0
  2885
  g_return_if_fail (signal_id > 0);
sl@0
  2886
sl@0
  2887
#ifdef G_ENABLE_DEBUG
sl@0
  2888
  param_values = instance_and_params + 1;
sl@0
  2889
#endif
sl@0
  2890
sl@0
  2891
  SIGNAL_LOCK ();
sl@0
  2892
  node = LOOKUP_SIGNAL_NODE (signal_id);
sl@0
  2893
  if (!node || !g_type_is_a (G_TYPE_FROM_INSTANCE (instance), node->itype))
sl@0
  2894
    {
sl@0
  2895
      g_warning ("%s: signal id `%u' is invalid for instance `%p'", G_STRLOC, signal_id, instance);
sl@0
  2896
      SIGNAL_UNLOCK ();
sl@0
  2897
      return;
sl@0
  2898
    }
sl@0
  2899
#ifdef G_ENABLE_DEBUG
sl@0
  2900
  if (detail && !(node->flags & G_SIGNAL_DETAILED))
sl@0
  2901
    {
sl@0
  2902
      g_warning ("%s: signal id `%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
sl@0
  2903
      SIGNAL_UNLOCK ();
sl@0
  2904
      return;
sl@0
  2905
    }
sl@0
  2906
  for (i = 0; i < node->n_params; i++)
sl@0
  2907
    if (!G_TYPE_CHECK_VALUE_TYPE (param_values + i, node->param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE))
sl@0
  2908
      {
sl@0
  2909
	g_critical ("%s: value for `%s' parameter %u for signal \"%s\" is of type `%s'",
sl@0
  2910
		    G_STRLOC,
sl@0
  2911
		    type_debug_name (node->param_types[i]),
sl@0
  2912
		    i,
sl@0
  2913
		    node->name,
sl@0
  2914
		    G_VALUE_TYPE_NAME (param_values + i));
sl@0
  2915
	SIGNAL_UNLOCK ();
sl@0
  2916
	return;
sl@0
  2917
      }
sl@0
  2918
  if (node->return_type != G_TYPE_NONE)
sl@0
  2919
    {
sl@0
  2920
      if (!return_value)
sl@0
  2921
	{
sl@0
  2922
	  g_critical ("%s: return value `%s' for signal \"%s\" is (NULL)",
sl@0
  2923
		      G_STRLOC,
sl@0
  2924
		      type_debug_name (node->return_type),
sl@0
  2925
		      node->name);
sl@0
  2926
	  SIGNAL_UNLOCK ();
sl@0
  2927
	  return;
sl@0
  2928
	}
sl@0
  2929
      else if (!node->accumulator && !G_TYPE_CHECK_VALUE_TYPE (return_value, node->return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE))
sl@0
  2930
	{
sl@0
  2931
	  g_critical ("%s: return value `%s' for signal \"%s\" is of type `%s'",
sl@0
  2932
		      G_STRLOC,
sl@0
  2933
		      type_debug_name (node->return_type),
sl@0
  2934
		      node->name,
sl@0
  2935
		      G_VALUE_TYPE_NAME (return_value));
sl@0
  2936
	  SIGNAL_UNLOCK ();
sl@0
  2937
	  return;
sl@0
  2938
	}
sl@0
  2939
    }
sl@0
  2940
  else
sl@0
  2941
    return_value = NULL;
sl@0
  2942
#endif	/* G_ENABLE_DEBUG */
sl@0
  2943
sl@0
  2944
  /* optimize NOP emissions */
sl@0
  2945
  if (signal_check_skip_emission (node, instance, detail))
sl@0
  2946
    {
sl@0
  2947
      /* nothing to do to emit this signal */
sl@0
  2948
      SIGNAL_UNLOCK ();
sl@0
  2949
      /* g_printerr ("omitting emission of \"%s\"\n", node->name); */
sl@0
  2950
      return;
sl@0
  2951
    }
sl@0
  2952
sl@0
  2953
  SIGNAL_UNLOCK ();
sl@0
  2954
  signal_emit_unlocked_R (node, detail, instance, return_value, instance_and_params);
sl@0
  2955
}
sl@0
  2956
sl@0
  2957
/**
sl@0
  2958
 * g_signal_emit_valist:
sl@0
  2959
 * @instance: the instance the signal is being emitted on.
sl@0
  2960
 * @signal_id: the signal id
sl@0
  2961
 * @detail: the detail
sl@0
  2962
 * @var_args: a list of parameters to be passed to the signal, followed by a
sl@0
  2963
 *  location for the return value. If the return type of the signal
sl@0
  2964
 *  is #G_TYPE_NONE, the return value location can be omitted.
sl@0
  2965
 *
sl@0
  2966
 * Emits a signal.
sl@0
  2967
 *
sl@0
  2968
 * Note that g_signal_emit_valist() resets the return value to the default
sl@0
  2969
 * if no handlers are connected, in contrast to g_signal_emitv().
sl@0
  2970
 */
sl@0
  2971
EXPORT_C void
sl@0
  2972
g_signal_emit_valist (gpointer instance,
sl@0
  2973
		      guint    signal_id,
sl@0
  2974
		      GQuark   detail,
sl@0
  2975
		      va_list  var_args)
sl@0
  2976
{
sl@0
  2977
  GValue *instance_and_params;
sl@0
  2978
  GType signal_return_type;
sl@0
  2979
  GValue *param_values;
sl@0
  2980
  SignalNode *node;
sl@0
  2981
  guint i, n_params;
sl@0
  2982
  
sl@0
  2983
  g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
sl@0
  2984
  g_return_if_fail (signal_id > 0);
sl@0
  2985
sl@0
  2986
  SIGNAL_LOCK ();
sl@0
  2987
  node = LOOKUP_SIGNAL_NODE (signal_id);
sl@0
  2988
  if (!node || !g_type_is_a (G_TYPE_FROM_INSTANCE (instance), node->itype))
sl@0
  2989
    {
sl@0
  2990
      g_warning ("%s: signal id `%u' is invalid for instance `%p'", G_STRLOC, signal_id, instance);
sl@0
  2991
      SIGNAL_UNLOCK ();
sl@0
  2992
      return;
sl@0
  2993
    }
sl@0
  2994
#ifndef G_DISABLE_CHECKS
sl@0
  2995
  if (detail && !(node->flags & G_SIGNAL_DETAILED))
sl@0
  2996
    {
sl@0
  2997
      g_warning ("%s: signal id `%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
sl@0
  2998
      SIGNAL_UNLOCK ();
sl@0
  2999
      return;
sl@0
  3000
    }
sl@0
  3001
#endif  /* !G_DISABLE_CHECKS */
sl@0
  3002
sl@0
  3003
  /* optimize NOP emissions */
sl@0
  3004
  if (signal_check_skip_emission (node, instance, detail))
sl@0
  3005
    {
sl@0
  3006
      /* nothing to do to emit this signal */
sl@0
  3007
      SIGNAL_UNLOCK ();
sl@0
  3008
      /* g_printerr ("omitting emission of \"%s\"\n", node->name); */
sl@0
  3009
      return;
sl@0
  3010
    }
sl@0
  3011
sl@0
  3012
  n_params = node->n_params;
sl@0
  3013
  signal_return_type = node->return_type;
sl@0
  3014
  instance_and_params = g_slice_alloc (sizeof (GValue) * (n_params + 1));
sl@0
  3015
  param_values = instance_and_params + 1;
sl@0
  3016
sl@0
  3017
  for (i = 0; i < node->n_params; i++)
sl@0
  3018
    {
sl@0
  3019
      gchar *error;
sl@0
  3020
      GType ptype = node->param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE;
sl@0
  3021
      gboolean static_scope = node->param_types[i] & G_SIGNAL_TYPE_STATIC_SCOPE;
sl@0
  3022
sl@0
  3023
      param_values[i].g_type = 0;
sl@0
  3024
      SIGNAL_UNLOCK ();
sl@0
  3025
      g_value_init (param_values + i, ptype);
sl@0
  3026
      G_VALUE_COLLECT (param_values + i,
sl@0
  3027
		       var_args,
sl@0
  3028
		       static_scope ? G_VALUE_NOCOPY_CONTENTS : 0,
sl@0
  3029
		       &error);
sl@0
  3030
      if (error)
sl@0
  3031
	{
sl@0
  3032
	  g_warning ("%s: %s", G_STRLOC, error);
sl@0
  3033
	  g_free (error);
sl@0
  3034
sl@0
  3035
	  /* we purposely leak the value here, it might not be
sl@0
  3036
	   * in a sane state if an error condition occoured
sl@0
  3037
	   */
sl@0
  3038
	  while (i--)
sl@0
  3039
	    g_value_unset (param_values + i);
sl@0
  3040
sl@0
  3041
	  g_slice_free1 (sizeof (GValue) * (n_params + 1), instance_and_params);
sl@0
  3042
	  return;
sl@0
  3043
	}
sl@0
  3044
      SIGNAL_LOCK ();
sl@0
  3045
    }
sl@0
  3046
  SIGNAL_UNLOCK ();
sl@0
  3047
  instance_and_params->g_type = 0;
sl@0
  3048
  g_value_init (instance_and_params, G_TYPE_FROM_INSTANCE (instance));
sl@0
  3049
  g_value_set_instance (instance_and_params, instance);
sl@0
  3050
  if (signal_return_type == G_TYPE_NONE)
sl@0
  3051
    signal_emit_unlocked_R (node, detail, instance, NULL, instance_and_params);
sl@0
  3052
  else
sl@0
  3053
    {
sl@0
  3054
      GValue return_value = { 0, };
sl@0
  3055
      gchar *error = NULL;
sl@0
  3056
      GType rtype = signal_return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE;
sl@0
  3057
      gboolean static_scope = signal_return_type & G_SIGNAL_TYPE_STATIC_SCOPE;
sl@0
  3058
      
sl@0
  3059
      g_value_init (&return_value, rtype);
sl@0
  3060
sl@0
  3061
      signal_emit_unlocked_R (node, detail, instance, &return_value, instance_and_params);
sl@0
  3062
sl@0
  3063
      G_VALUE_LCOPY (&return_value,
sl@0
  3064
		     var_args,
sl@0
  3065
		     static_scope ? G_VALUE_NOCOPY_CONTENTS : 0,
sl@0
  3066
		     &error);
sl@0
  3067
      if (!error)
sl@0
  3068
	g_value_unset (&return_value);
sl@0
  3069
      else
sl@0
  3070
	{
sl@0
  3071
	  g_warning ("%s: %s", G_STRLOC, error);
sl@0
  3072
	  g_free (error);
sl@0
  3073
	  
sl@0
  3074
	  /* we purposely leak the value here, it might not be
sl@0
  3075
	   * in a sane state if an error condition occured
sl@0
  3076
	   */
sl@0
  3077
	}
sl@0
  3078
    }
sl@0
  3079
  for (i = 0; i < n_params; i++)
sl@0
  3080
    g_value_unset (param_values + i);
sl@0
  3081
  g_value_unset (instance_and_params);
sl@0
  3082
  g_slice_free1 (sizeof (GValue) * (n_params + 1), instance_and_params);
sl@0
  3083
}
sl@0
  3084
sl@0
  3085
/**
sl@0
  3086
 * g_signal_emit:
sl@0
  3087
 * @instance: the instance the signal is being emitted on.
sl@0
  3088
 * @signal_id: the signal id
sl@0
  3089
 * @detail: the detail
sl@0
  3090
 * @...: parameters to be passed to the signal, followed by a
sl@0
  3091
 *  location for the return value. If the return type of the signal
sl@0
  3092
 *  is #G_TYPE_NONE, the return value location can be omitted.
sl@0
  3093
 *
sl@0
  3094
 * Emits a signal.
sl@0
  3095
 *
sl@0
  3096
 * Note that g_signal_emit() resets the return value to the default
sl@0
  3097
 * if no handlers are connected, in contrast to g_signal_emitv().
sl@0
  3098
 */
sl@0
  3099
EXPORT_C void
sl@0
  3100
g_signal_emit (gpointer instance,
sl@0
  3101
	       guint    signal_id,
sl@0
  3102
	       GQuark   detail,
sl@0
  3103
	       ...)
sl@0
  3104
{
sl@0
  3105
  va_list var_args;
sl@0
  3106
sl@0
  3107
  va_start (var_args, detail);
sl@0
  3108
  g_signal_emit_valist (instance, signal_id, detail, var_args);
sl@0
  3109
  va_end (var_args);
sl@0
  3110
}
sl@0
  3111
sl@0
  3112
/**
sl@0
  3113
 * g_signal_emit_by_name:
sl@0
  3114
 * @instance: the instance the signal is being emitted on.
sl@0
  3115
 * @detailed_signal: a string of the form "signal-name::detail".
sl@0
  3116
 * @...: parameters to be passed to the signal, followed by a
sl@0
  3117
 *  location for the return value. If the return type of the signal
sl@0
  3118
 *  is #G_TYPE_NONE, the return value location can be omitted.
sl@0
  3119
 *
sl@0
  3120
 * Emits a signal.
sl@0
  3121
 *
sl@0
  3122
 * Note that g_signal_emit_by_name() resets the return value to the default
sl@0
  3123
 * if no handlers are connected, in contrast to g_signal_emitv().
sl@0
  3124
 */
sl@0
  3125
EXPORT_C void
sl@0
  3126
g_signal_emit_by_name (gpointer     instance,
sl@0
  3127
		       const gchar *detailed_signal,
sl@0
  3128
		       ...)
sl@0
  3129
{
sl@0
  3130
  GQuark detail = 0;
sl@0
  3131
  guint signal_id;
sl@0
  3132
sl@0
  3133
  g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
sl@0
  3134
  g_return_if_fail (detailed_signal != NULL);
sl@0
  3135
sl@0
  3136
  SIGNAL_LOCK ();
sl@0
  3137
  signal_id = signal_parse_name (detailed_signal, G_TYPE_FROM_INSTANCE (instance), &detail, TRUE);
sl@0
  3138
  SIGNAL_UNLOCK ();
sl@0
  3139
sl@0
  3140
  if (signal_id)
sl@0
  3141
    {
sl@0
  3142
      va_list var_args;
sl@0
  3143
sl@0
  3144
      va_start (var_args, detailed_signal);
sl@0
  3145
      g_signal_emit_valist (instance, signal_id, detail, var_args);
sl@0
  3146
      va_end (var_args);
sl@0
  3147
    }
sl@0
  3148
  else
sl@0
  3149
    g_warning ("%s: signal name `%s' is invalid for instance `%p'", G_STRLOC, detailed_signal, instance);
sl@0
  3150
}
sl@0
  3151
sl@0
  3152
static inline gboolean
sl@0
  3153
accumulate (GSignalInvocationHint *ihint,
sl@0
  3154
	    GValue                *return_accu,
sl@0
  3155
	    GValue	          *handler_return,
sl@0
  3156
	    SignalAccumulator     *accumulator)
sl@0
  3157
{
sl@0
  3158
  gboolean continue_emission;
sl@0
  3159
sl@0
  3160
  if (!accumulator)
sl@0
  3161
    return TRUE;
sl@0
  3162
sl@0
  3163
  continue_emission = accumulator->func (ihint, return_accu, handler_return, accumulator->data);
sl@0
  3164
  g_value_reset (handler_return);
sl@0
  3165
sl@0
  3166
  return continue_emission;
sl@0
  3167
}
sl@0
  3168
sl@0
  3169
static gboolean
sl@0
  3170
signal_emit_unlocked_R (SignalNode   *node,
sl@0
  3171
			GQuark	      detail,
sl@0
  3172
			gpointer      instance,
sl@0
  3173
			GValue	     *emission_return,
sl@0
  3174
			const GValue *instance_and_params)
sl@0
  3175
{
sl@0
  3176
  SignalAccumulator *accumulator;
sl@0
  3177
  Emission emission;
sl@0
  3178
  GClosure *class_closure;
sl@0
  3179
  HandlerList *hlist;
sl@0
  3180
  Handler *handler_list = NULL;
sl@0
  3181
  GValue *return_accu, accu = { 0, };
sl@0
  3182
  guint signal_id;
sl@0
  3183
  gulong max_sequential_handler_number;
sl@0
  3184
  gboolean return_value_altered = FALSE;
sl@0
  3185
  
sl@0
  3186
#ifdef	G_ENABLE_DEBUG
sl@0
  3187
  IF_DEBUG (SIGNALS, g_trace_instance_signals == instance || g_trap_instance_signals == instance)
sl@0
  3188
    {
sl@0
  3189
      g_message ("%s::%s(%u) emitted (instance=%p, signal-node=%p)",
sl@0
  3190
		 g_type_name (G_TYPE_FROM_INSTANCE (instance)),
sl@0
  3191
		 node->name, detail,
sl@0
  3192
		 instance, node);
sl@0
  3193
      if (g_trap_instance_signals == instance)
sl@0
  3194
	G_BREAKPOINT ();
sl@0
  3195
    }
sl@0
  3196
#endif	/* G_ENABLE_DEBUG */
sl@0
  3197
  
sl@0
  3198
  SIGNAL_LOCK ();
sl@0
  3199
  signal_id = node->signal_id;
sl@0
  3200
  if (node->flags & G_SIGNAL_NO_RECURSE)
sl@0
  3201
    {
sl@0
  3202
      Emission *node = emission_find (g_restart_emissions, signal_id, detail, instance);
sl@0
  3203
      
sl@0
  3204
      if (node)
sl@0
  3205
	{
sl@0
  3206
	  node->state = EMISSION_RESTART;
sl@0
  3207
	  SIGNAL_UNLOCK ();
sl@0
  3208
	  return return_value_altered;
sl@0
  3209
	}
sl@0
  3210
    }
sl@0
  3211
  accumulator = node->accumulator;
sl@0
  3212
  if (accumulator)
sl@0
  3213
    {
sl@0
  3214
      SIGNAL_UNLOCK ();
sl@0
  3215
      g_value_init (&accu, node->return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE);
sl@0
  3216
      return_accu = &accu;
sl@0
  3217
      SIGNAL_LOCK ();
sl@0
  3218
    }
sl@0
  3219
  else
sl@0
  3220
    return_accu = emission_return;
sl@0
  3221
  emission.instance = instance;
sl@0
  3222
  emission.ihint.signal_id = node->signal_id;
sl@0
  3223
  emission.ihint.detail = detail;
sl@0
  3224
  emission.ihint.run_type = 0;
sl@0
  3225
  emission.state = 0;
sl@0
  3226
  emission.chain_type = G_TYPE_NONE;
sl@0
  3227
  emission_push ((node->flags & G_SIGNAL_NO_RECURSE) ? &g_restart_emissions : &g_recursive_emissions, &emission);
sl@0
  3228
  class_closure = signal_lookup_closure (node, instance);
sl@0
  3229
  
sl@0
  3230
 EMIT_RESTART:
sl@0
  3231
  
sl@0
  3232
  if (handler_list)
sl@0
  3233
    handler_unref_R (signal_id, instance, handler_list);
sl@0
  3234
  max_sequential_handler_number = g_handler_sequential_number;
sl@0
  3235
  hlist = handler_list_lookup (signal_id, instance);
sl@0
  3236
  handler_list = hlist ? hlist->handlers : NULL;
sl@0
  3237
  if (handler_list)
sl@0
  3238
    handler_ref (handler_list);
sl@0
  3239
  
sl@0
  3240
  emission.ihint.run_type = G_SIGNAL_RUN_FIRST;
sl@0
  3241
  
sl@0
  3242
  if ((node->flags & G_SIGNAL_RUN_FIRST) && class_closure)
sl@0
  3243
    {
sl@0
  3244
      emission.state = EMISSION_RUN;
sl@0
  3245
sl@0
  3246
      emission.chain_type = G_TYPE_FROM_INSTANCE (instance);
sl@0
  3247
      SIGNAL_UNLOCK ();
sl@0
  3248
      g_closure_invoke (class_closure,
sl@0
  3249
			return_accu,
sl@0
  3250
			node->n_params + 1,
sl@0
  3251
			instance_and_params,
sl@0
  3252
			&emission.ihint);
sl@0
  3253
      if (!accumulate (&emission.ihint, emission_return, &accu, accumulator) &&
sl@0
  3254
	  emission.state == EMISSION_RUN)
sl@0
  3255
	emission.state = EMISSION_STOP;
sl@0
  3256
      SIGNAL_LOCK ();
sl@0
  3257
      emission.chain_type = G_TYPE_NONE;
sl@0
  3258
      return_value_altered = TRUE;
sl@0
  3259
      
sl@0
  3260
      if (emission.state == EMISSION_STOP)
sl@0
  3261
	goto EMIT_CLEANUP;
sl@0
  3262
      else if (emission.state == EMISSION_RESTART)
sl@0
  3263
	goto EMIT_RESTART;
sl@0
  3264
    }
sl@0
  3265
  
sl@0
  3266
  if (node->emission_hooks)
sl@0
  3267
    {
sl@0
  3268
      gboolean need_destroy, was_in_call, may_recurse = TRUE;
sl@0
  3269
      GHook *hook;
sl@0
  3270
sl@0
  3271
      emission.state = EMISSION_HOOK;
sl@0
  3272
      hook = g_hook_first_valid (node->emission_hooks, may_recurse);
sl@0
  3273
      while (hook)
sl@0
  3274
	{
sl@0
  3275
	  SignalHook *signal_hook = SIGNAL_HOOK (hook);
sl@0
  3276
	  
sl@0
  3277
	  if (!signal_hook->detail || signal_hook->detail == detail)
sl@0
  3278
	    {
sl@0
  3279
	      GSignalEmissionHook hook_func = (GSignalEmissionHook) hook->func;
sl@0
  3280
	      
sl@0
  3281
	      was_in_call = G_HOOK_IN_CALL (hook);
sl@0
  3282
	      hook->flags |= G_HOOK_FLAG_IN_CALL;
sl@0
  3283
              SIGNAL_UNLOCK ();
sl@0
  3284
	      need_destroy = !hook_func (&emission.ihint, node->n_params + 1, instance_and_params, hook->data);
sl@0
  3285
	      SIGNAL_LOCK ();
sl@0
  3286
	      if (!was_in_call)
sl@0
  3287
		hook->flags &= ~G_HOOK_FLAG_IN_CALL;
sl@0
  3288
	      if (need_destroy)
sl@0
  3289
		g_hook_destroy_link (node->emission_hooks, hook);
sl@0
  3290
	    }
sl@0
  3291
	  hook = g_hook_next_valid (node->emission_hooks, hook, may_recurse);
sl@0
  3292
	}
sl@0
  3293
      
sl@0
  3294
      if (emission.state == EMISSION_RESTART)
sl@0
  3295
	goto EMIT_RESTART;
sl@0
  3296
    }
sl@0
  3297
  
sl@0
  3298
  if (handler_list)
sl@0
  3299
    {
sl@0
  3300
      Handler *handler = handler_list;
sl@0
  3301
      
sl@0
  3302
      emission.state = EMISSION_RUN;
sl@0
  3303
      handler_ref (handler);
sl@0
  3304
      do
sl@0
  3305
	{
sl@0
  3306
	  Handler *tmp;
sl@0
  3307
	  
sl@0
  3308
	  if (handler->after)
sl@0
  3309
	    {
sl@0
  3310
	      handler_unref_R (signal_id, instance, handler_list);
sl@0
  3311
	      handler_list = handler;
sl@0
  3312
	      break;
sl@0
  3313
	    }
sl@0
  3314
	  else if (!handler->block_count && (!handler->detail || handler->detail == detail) &&
sl@0
  3315
		   handler->sequential_number < max_sequential_handler_number)
sl@0
  3316
	    {
sl@0
  3317
	      SIGNAL_UNLOCK ();
sl@0
  3318
	      g_closure_invoke (handler->closure,
sl@0
  3319
				return_accu,
sl@0
  3320
				node->n_params + 1,
sl@0
  3321
				instance_and_params,
sl@0
  3322
				&emission.ihint);
sl@0
  3323
	      if (!accumulate (&emission.ihint, emission_return, &accu, accumulator) &&
sl@0
  3324
		  emission.state == EMISSION_RUN)
sl@0
  3325
		emission.state = EMISSION_STOP;
sl@0
  3326
	      SIGNAL_LOCK ();
sl@0
  3327
	      return_value_altered = TRUE;
sl@0
  3328
	      
sl@0
  3329
	      tmp = emission.state == EMISSION_RUN ? handler->next : NULL;
sl@0
  3330
	    }
sl@0
  3331
	  else
sl@0
  3332
	    tmp = handler->next;
sl@0
  3333
	  
sl@0
  3334
	  if (tmp)
sl@0
  3335
	    handler_ref (tmp);
sl@0
  3336
	  handler_unref_R (signal_id, instance, handler_list);
sl@0
  3337
	  handler_list = handler;
sl@0
  3338
	  handler = tmp;
sl@0
  3339
	}
sl@0
  3340
      while (handler);
sl@0
  3341
      
sl@0
  3342
      if (emission.state == EMISSION_STOP)
sl@0
  3343
	goto EMIT_CLEANUP;
sl@0
  3344
      else if (emission.state == EMISSION_RESTART)
sl@0
  3345
	goto EMIT_RESTART;
sl@0
  3346
    }
sl@0
  3347
  
sl@0
  3348
  emission.ihint.run_type = G_SIGNAL_RUN_LAST;
sl@0
  3349
  
sl@0
  3350
  if ((node->flags & G_SIGNAL_RUN_LAST) && class_closure)
sl@0
  3351
    {
sl@0
  3352
      emission.state = EMISSION_RUN;
sl@0
  3353
      
sl@0
  3354
      emission.chain_type = G_TYPE_FROM_INSTANCE (instance);
sl@0
  3355
      SIGNAL_UNLOCK ();
sl@0
  3356
      g_closure_invoke (class_closure,
sl@0
  3357
			return_accu,
sl@0
  3358
			node->n_params + 1,
sl@0
  3359
			instance_and_params,
sl@0
  3360
			&emission.ihint);
sl@0
  3361
      if (!accumulate (&emission.ihint, emission_return, &accu, accumulator) &&
sl@0
  3362
	  emission.state == EMISSION_RUN)
sl@0
  3363
	emission.state = EMISSION_STOP;
sl@0
  3364
      SIGNAL_LOCK ();
sl@0
  3365
      emission.chain_type = G_TYPE_NONE;
sl@0
  3366
      return_value_altered = TRUE;
sl@0
  3367
      
sl@0
  3368
      if (emission.state == EMISSION_STOP)
sl@0
  3369
	goto EMIT_CLEANUP;
sl@0
  3370
      else if (emission.state == EMISSION_RESTART)
sl@0
  3371
	goto EMIT_RESTART;
sl@0
  3372
    }
sl@0
  3373
  
sl@0
  3374
  if (handler_list)
sl@0
  3375
    {
sl@0
  3376
      Handler *handler = handler_list;
sl@0
  3377
      
sl@0
  3378
      emission.state = EMISSION_RUN;
sl@0
  3379
      handler_ref (handler);
sl@0
  3380
      do
sl@0
  3381
	{
sl@0
  3382
	  Handler *tmp;
sl@0
  3383
	  
sl@0
  3384
	  if (handler->after && !handler->block_count && (!handler->detail || handler->detail == detail) &&
sl@0
  3385
	      handler->sequential_number < max_sequential_handler_number)
sl@0
  3386
	    {
sl@0
  3387
	      SIGNAL_UNLOCK ();
sl@0
  3388
	      g_closure_invoke (handler->closure,
sl@0
  3389
				return_accu,
sl@0
  3390
				node->n_params + 1,
sl@0
  3391
				instance_and_params,
sl@0
  3392
				&emission.ihint);
sl@0
  3393
	      if (!accumulate (&emission.ihint, emission_return, &accu, accumulator) &&
sl@0
  3394
		  emission.state == EMISSION_RUN)
sl@0
  3395
		emission.state = EMISSION_STOP;
sl@0
  3396
	      SIGNAL_LOCK ();
sl@0
  3397
	      return_value_altered = TRUE;
sl@0
  3398
	      
sl@0
  3399
	      tmp = emission.state == EMISSION_RUN ? handler->next : NULL;
sl@0
  3400
	    }
sl@0
  3401
	  else
sl@0
  3402
	    tmp = handler->next;
sl@0
  3403
	  
sl@0
  3404
	  if (tmp)
sl@0
  3405
	    handler_ref (tmp);
sl@0
  3406
	  handler_unref_R (signal_id, instance, handler);
sl@0
  3407
	  handler = tmp;
sl@0
  3408
	}
sl@0
  3409
      while (handler);
sl@0
  3410
      
sl@0
  3411
      if (emission.state == EMISSION_STOP)
sl@0
  3412
	goto EMIT_CLEANUP;
sl@0
  3413
      else if (emission.state == EMISSION_RESTART)
sl@0
  3414
	goto EMIT_RESTART;
sl@0
  3415
    }
sl@0
  3416
  
sl@0
  3417
 EMIT_CLEANUP:
sl@0
  3418
  
sl@0
  3419
  emission.ihint.run_type = G_SIGNAL_RUN_CLEANUP;
sl@0
  3420
  
sl@0
  3421
  if ((node->flags & G_SIGNAL_RUN_CLEANUP) && class_closure)
sl@0
  3422
    {
sl@0
  3423
      gboolean need_unset = FALSE;
sl@0
  3424
      
sl@0
  3425
      emission.state = EMISSION_STOP;
sl@0
  3426
      
sl@0
  3427
      emission.chain_type = G_TYPE_FROM_INSTANCE (instance);
sl@0
  3428
      SIGNAL_UNLOCK ();
sl@0
  3429
      if (node->return_type != G_TYPE_NONE && !accumulator)
sl@0
  3430
	{
sl@0
  3431
	  g_value_init (&accu, node->return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE);
sl@0
  3432
	  need_unset = TRUE;
sl@0
  3433
	}
sl@0
  3434
      g_closure_invoke (class_closure,
sl@0
  3435
			node->return_type != G_TYPE_NONE ? &accu : NULL,
sl@0
  3436
			node->n_params + 1,
sl@0
  3437
			instance_and_params,
sl@0
  3438
			&emission.ihint);
sl@0
  3439
      if (need_unset)
sl@0
  3440
	g_value_unset (&accu);
sl@0
  3441
      SIGNAL_LOCK ();
sl@0
  3442
      emission.chain_type = G_TYPE_NONE;
sl@0
  3443
      
sl@0
  3444
      if (emission.state == EMISSION_RESTART)
sl@0
  3445
	goto EMIT_RESTART;
sl@0
  3446
    }
sl@0
  3447
  
sl@0
  3448
  if (handler_list)
sl@0
  3449
    handler_unref_R (signal_id, instance, handler_list);
sl@0
  3450
  
sl@0
  3451
  emission_pop ((node->flags & G_SIGNAL_NO_RECURSE) ? &g_restart_emissions : &g_recursive_emissions, &emission);
sl@0
  3452
  SIGNAL_UNLOCK ();
sl@0
  3453
  if (accumulator)
sl@0
  3454
    g_value_unset (&accu);
sl@0
  3455
  
sl@0
  3456
  return return_value_altered;
sl@0
  3457
}
sl@0
  3458
sl@0
  3459
static const gchar*
sl@0
  3460
type_debug_name (GType type)
sl@0
  3461
{
sl@0
  3462
  if (type)
sl@0
  3463
    {
sl@0
  3464
      const char *name = g_type_name (type & ~G_SIGNAL_TYPE_STATIC_SCOPE);
sl@0
  3465
      return name ? name : "<unknown>";
sl@0
  3466
    }
sl@0
  3467
  else
sl@0
  3468
    return "<invalid>";
sl@0
  3469
}
sl@0
  3470
sl@0
  3471
/**
sl@0
  3472
 * g_signal_accumulator_true_handled:
sl@0
  3473
 * @ihint: standard #GSignalAccumulator parameter
sl@0
  3474
 * @return_accu: standard #GSignalAccumulator parameter
sl@0
  3475
 * @handler_return: standard #GSignalAccumulator parameter
sl@0
  3476
 * @dummy: standard #GSignalAccumulator parameter
sl@0
  3477
 *
sl@0
  3478
 * A predefined #GSignalAccumulator for signals that return a
sl@0
  3479
 * boolean values. The behavior that this accumulator gives is
sl@0
  3480
 * that a return of %TRUE stops the signal emission: no further
sl@0
  3481
 * callbacks will be invoked, while a return of %FALSE allows
sl@0
  3482
 * the emission to coninue. The idea here is that a %TRUE return
sl@0
  3483
 * indicates that the callback <emphasis>handled</emphasis> the signal,
sl@0
  3484
 * and no further handling is needed.
sl@0
  3485
 *
sl@0
  3486
 * Since: 2.4
sl@0
  3487
 *
sl@0
  3488
 * Returns: standard #GSignalAccumulator result
sl@0
  3489
 */
sl@0
  3490
EXPORT_C gboolean
sl@0
  3491
g_signal_accumulator_true_handled (GSignalInvocationHint *ihint,
sl@0
  3492
				   GValue                *return_accu,
sl@0
  3493
				   const GValue          *handler_return,
sl@0
  3494
				   gpointer               dummy)
sl@0
  3495
{
sl@0
  3496
  gboolean continue_emission;
sl@0
  3497
  gboolean signal_handled;
sl@0
  3498
  
sl@0
  3499
  signal_handled = g_value_get_boolean (handler_return);
sl@0
  3500
  g_value_set_boolean (return_accu, signal_handled);
sl@0
  3501
  continue_emission = !signal_handled;
sl@0
  3502
  
sl@0
  3503
  return continue_emission;
sl@0
  3504
}
sl@0
  3505
sl@0
  3506
/* --- compile standard marshallers --- */
sl@0
  3507
#include "gmarshal.c"
sl@0
  3508
sl@0
  3509
#define __G_SIGNAL_C__
sl@0
  3510
#include "gobjectaliasdef.c"