diff options
author | Timo Sirainen <cras@irssi.org> | 2001-01-03 07:34:12 +0000 |
---|---|---|
committer | cras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2001-01-03 07:34:12 +0000 |
commit | 1e4c658a188456e957dd99d07b70aa23be5c0dcb (patch) | |
tree | b533cd728d6f5120e7835aa2a9fb53aa630dd31d /src/core | |
parent | db66d47e26965c46d7449b7e197f58be58e91ed3 (diff) | |
download | irssi-1e4c658a188456e957dd99d07b70aa23be5c0dcb.zip |
Removed the "signal" and "last signal" signals. Changed perl's
signaling system to work without them, it should now work faster and
better.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1053 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/signals.c | 65 | ||||
-rw-r--r-- | src/core/signals.h | 13 |
2 files changed, 40 insertions, 38 deletions
diff --git a/src/core/signals.c b/src/core/signals.c index 3c1e4281..d1416a79 100644 --- a/src/core/signals.c +++ b/src/core/signals.c @@ -25,6 +25,8 @@ #define SIGNAL_LISTS 3 typedef struct { + int id; /* signal id */ + int emitting; /* signal is being emitted */ int altered; /* some signal functions are marked as NULL */ int stop_emit; /* this signal was stopped */ @@ -39,8 +41,6 @@ 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, @@ -64,14 +64,10 @@ void signal_add_to_id(const char *module, int pos, rec = g_hash_table_lookup(signals, GINT_TO_POINTER(signal_id)); if (rec == NULL) { rec = g_mem_chunk_alloc0(signals_chunk); + rec->id = signal_id; g_hash_table_insert(signals, GINT_TO_POINTER(signal_id), rec); } - if (signal_id == first_signal_id) - first_signal_rec = rec; - else if (signal_id == last_signal_id) - last_signal_rec = rec; - if (rec->siglist[pos] == NULL) { rec->siglist[pos] = g_ptr_array_new(); rec->modulelist[pos] = g_ptr_array_new(); @@ -92,11 +88,6 @@ static void signal_destroy(int signal_id) g_hash_table_remove(signals, GINT_TO_POINTER(signal_id)); g_free(rec); } - - if (first_signal_rec == rec) - first_signal_rec = NULL; - else if (last_signal_rec == rec) - last_signal_rec = NULL; } static int signal_list_find(GPtrArray *array, void *data) @@ -207,7 +198,10 @@ static int signal_emit_real(SIGNAL_REC *rec, gconstpointer *arglist) if (func != NULL) { prev_emitted_signal = current_emitted_signal; current_emitted_signal = rec; - func(arglist[0], arglist[1], arglist[2], arglist[3], arglist[4], arglist[5], arglist[6]); +#if SIGNAL_MAX_ARGUMENTS != 6 +# error SIGNAL_MAX_ARGS changed - update code +#endif + func(arglist[0], arglist[1], arglist[2], arglist[3], arglist[4], arglist[5]); current_emitted_signal = prev_emitted_signal; } @@ -237,33 +231,20 @@ static int signal_emit_real(SIGNAL_REC *rec, gconstpointer *arglist) static int signal_emitv_id(int signal_id, int params, va_list va) { - gconstpointer arglist[8]; + gconstpointer arglist[SIGNAL_MAX_ARGUMENTS]; SIGNAL_REC *rec; int n; g_return_val_if_fail(signal_id >= 0, FALSE); - g_return_val_if_fail(params >= 0 && params <= sizeof(arglist)/sizeof(arglist[0]), FALSE); + g_return_val_if_fail(params >= 0 && params <= SIGNAL_MAX_ARGUMENTS, FALSE); - arglist[0] = GINT_TO_POINTER(signal_id); - for (n = 1; n < 8; n++) + for (n = 0; n < SIGNAL_MAX_ARGUMENTS; n++) arglist[n] = n > params ? NULL : va_arg(va, gconstpointer); - /* send "signal" */ - if (first_signal_rec != NULL) { - if (signal_emit_real(first_signal_rec, arglist)) - return TRUE; - } - rec = g_hash_table_lookup(signals, GINT_TO_POINTER(signal_id)); - if (rec != NULL && signal_emit_real(rec, arglist+1)) + if (rec != NULL && signal_emit_real(rec, arglist)) return TRUE; - /* send "last signal" */ - if (last_signal_rec != NULL) { - if (signal_emit_real(last_signal_rec, arglist)) - return TRUE; - } - return rec != NULL; } @@ -323,7 +304,24 @@ void signal_stop_by_name(const char *signal) rec->stop_emit++; } -static void signal_remove_module(void *signal, SIGNAL_REC *rec, const char *module) +/* return the name of the signal that is currently being emitted */ +const char *signal_get_emitted(void) +{ + return signal_get_id_str(signal_get_emitted_id()); +} + +/* return the ID of the signal that is currently being emitted */ +int signal_get_emitted_id(void) +{ + SIGNAL_REC *rec; + + rec = current_emitted_signal; + g_return_val_if_fail(rec != NULL, -1); + return rec->id; +} + +static void signal_remove_module(void *signal, SIGNAL_REC *rec, + const char *module) { unsigned int index; int signal_id, list; @@ -354,11 +352,6 @@ void signals_init(void) signals_chunk = g_mem_chunk_new("signals", sizeof(SIGNAL_REC), sizeof(SIGNAL_REC)*200, G_ALLOC_AND_FREE); signals = g_hash_table_new((GHashFunc) g_direct_hash, (GCompareFunc) g_direct_equal); - - 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 f1fabf6c..d3fc41bd 100644 --- a/src/core/signals.h +++ b/src/core/signals.h @@ -1,16 +1,20 @@ #ifndef __SIGNAL_H #define __SIGNAL_H +#define SIGNAL_MAX_ARGUMENTS 6 typedef void (*SIGNAL_FUNC) (gconstpointer, gconstpointer, gconstpointer, gconstpointer, - gconstpointer, gconstpointer, gconstpointer); + gconstpointer, gconstpointer); void signals_init(void); void signals_deinit(void); -/* use this macro to convert the signal name to ID */ +/* signal name -> ID */ #define signal_get_uniq_id(signal) \ module_get_uniq_id_str("signals", signal) +/* signal ID -> name */ +#define signal_get_id_str(signal_id) \ + module_find_id_str("signals", signal_id) /* bind a signal */ void signal_add_to(const char *module, int pos, @@ -34,6 +38,11 @@ void signal_stop(void); /* stop ongoing signal emission by signal name */ void signal_stop_by_name(const char *signal); +/* return the name of the signal that is currently being emitted */ +const char *signal_get_emitted(void); +/* return the ID of the signal that is currently being emitted */ +int signal_get_emitted_id(void); + /* remove all signals that belong to `module' */ void signals_remove_module(const char *module); |