diff --git a/src/core/signals.c b/src/core/signals.c index 0fecd5c2..710d0687 100644 --- a/src/core/signals.c +++ b/src/core/signals.c @@ -39,31 +39,37 @@ typedef struct { static GMemChunk *signals_chunk; static GHashTable *signals; +static int first_signal_id, last_signal_id; static SIGNAL_REC *first_signal_rec, *last_signal_rec; /* "signal" and "last signal" */ static SIGNAL_REC *current_emitted_signal; +void signal_add_to(const char *module, int pos, + const char *signal, SIGNAL_FUNC func) +{ + g_return_if_fail(signal != NULL); + + signal_add_to_id(module, pos, signal_get_uniq_id(signal), func); +} + /* bind a signal */ -void signal_add_to(const char *module, int pos, const char *signal, - SIGNAL_FUNC func) +void signal_add_to_id(const char *module, int pos, + int signal_id, SIGNAL_FUNC func) { SIGNAL_REC *rec; - int signal_id; - g_return_if_fail(signal != NULL); + g_return_if_fail(signal_id >= 0); g_return_if_fail(func != NULL); g_return_if_fail(pos >= 0 && pos < SIGNAL_LISTS); - signal_id = signal_get_uniq_id(signal); - rec = g_hash_table_lookup(signals, GINT_TO_POINTER(signal_id)); if (rec == NULL) { rec = g_mem_chunk_alloc0(signals_chunk); g_hash_table_insert(signals, GINT_TO_POINTER(signal_id), rec); } - if (strcmp(signal, "signal") == 0) + if (signal_id == first_signal_id) first_signal_rec = rec; - else if (strcmp(signal, "last signal") == 0) + else if (signal_id == last_signal_id) last_signal_rec = rec; if (rec->siglist[pos] == NULL) { @@ -352,6 +358,8 @@ void signals_init(void) first_signal_rec = NULL; last_signal_rec = NULL; + first_signal_id = signal_get_uniq_id("signal"); + last_signal_id = signal_get_uniq_id("last signal"); } static void signal_free(void *key, SIGNAL_REC *rec) diff --git a/src/core/signals.h b/src/core/signals.h index ad684ab5..24e0ecbf 100644 --- a/src/core/signals.h +++ b/src/core/signals.h @@ -1,7 +1,9 @@ #ifndef __SIGNAL_H #define __SIGNAL_H -typedef void (*SIGNAL_FUNC) (gconstpointer, gconstpointer, gconstpointer, gconstpointer, gconstpointer, gconstpointer, gconstpointer); +typedef void (*SIGNAL_FUNC) (gconstpointer, gconstpointer, + gconstpointer, gconstpointer, + gconstpointer, gconstpointer, gconstpointer); void signals_init(void); void signals_deinit(void); @@ -11,7 +13,10 @@ void signals_deinit(void); module_get_uniq_id_str("signals", signal) /* bind a signal */ -void signal_add_to(const char *module, int pos, const char *signal, SIGNAL_FUNC func); +void signal_add_to(const char *module, int pos, + const char *signal, SIGNAL_FUNC func); +void signal_add_to_id(const char *module, int pos, + int signal, SIGNAL_FUNC func); #define signal_add(a, b) signal_add_to(MODULE_NAME, 1, a, b) #define signal_add_first(a, b) signal_add_to(MODULE_NAME, 0, a, b) #define signal_add_last(a, b) signal_add_to(MODULE_NAME, 2, a, b)