1
0
mirror of https://github.com/irssi/irssi.git synced 2024-12-04 14:46:39 -05:00

added signal_add_to_id()

git-svn-id: http://svn.irssi.org/repos/irssi/trunk@963 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2000-12-04 23:53:28 +00:00 committed by cras
parent 1c9f45b4a4
commit 5f941b8fa6
2 changed files with 23 additions and 10 deletions

View File

@ -39,31 +39,37 @@ typedef struct {
static GMemChunk *signals_chunk; static GMemChunk *signals_chunk;
static GHashTable *signals; 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 *first_signal_rec, *last_signal_rec; /* "signal" and "last signal" */
static SIGNAL_REC *current_emitted_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 */ /* bind a signal */
void signal_add_to(const char *module, int pos, const char *signal, void signal_add_to_id(const char *module, int pos,
SIGNAL_FUNC func) int signal_id, SIGNAL_FUNC func)
{ {
SIGNAL_REC *rec; 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(func != NULL);
g_return_if_fail(pos >= 0 && pos < SIGNAL_LISTS); 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)); rec = g_hash_table_lookup(signals, GINT_TO_POINTER(signal_id));
if (rec == NULL) { if (rec == NULL) {
rec = g_mem_chunk_alloc0(signals_chunk); rec = g_mem_chunk_alloc0(signals_chunk);
g_hash_table_insert(signals, GINT_TO_POINTER(signal_id), rec); 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; first_signal_rec = rec;
else if (strcmp(signal, "last signal") == 0) else if (signal_id == last_signal_id)
last_signal_rec = rec; last_signal_rec = rec;
if (rec->siglist[pos] == NULL) { if (rec->siglist[pos] == NULL) {
@ -352,6 +358,8 @@ void signals_init(void)
first_signal_rec = NULL; first_signal_rec = NULL;
last_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) static void signal_free(void *key, SIGNAL_REC *rec)

View File

@ -1,7 +1,9 @@
#ifndef __SIGNAL_H #ifndef __SIGNAL_H
#define __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_init(void);
void signals_deinit(void); void signals_deinit(void);
@ -11,7 +13,10 @@ void signals_deinit(void);
module_get_uniq_id_str("signals", signal) module_get_uniq_id_str("signals", signal)
/* bind a 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(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_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) #define signal_add_last(a, b) signal_add_to(MODULE_NAME, 2, a, b)