mirror of
https://github.com/irssi/irssi.git
synced 2026-08-11 04:43:34 +02:00
fixes for new signaling code.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2691 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
c5b852ed57
commit
c7320514aa
7 changed files with 123 additions and 159 deletions
|
|
@ -72,10 +72,10 @@ static COMMAND_MODULE_REC *command_module_find(COMMAND_REC *rec,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static COMMAND_MODULE_REC *command_module_find_func(COMMAND_REC *rec,
|
||||
SIGNAL_FUNC func)
|
||||
static COMMAND_MODULE_REC *
|
||||
command_module_find_and_remove(COMMAND_REC *rec, SIGNAL_FUNC func)
|
||||
{
|
||||
GSList *tmp;
|
||||
GSList *tmp, *tmp2;
|
||||
|
||||
g_return_val_if_fail(rec != NULL, NULL);
|
||||
g_return_val_if_fail(func != NULL, NULL);
|
||||
|
|
@ -83,8 +83,15 @@ static COMMAND_MODULE_REC *command_module_find_func(COMMAND_REC *rec,
|
|||
for (tmp = rec->modules; tmp != NULL; tmp = tmp->next) {
|
||||
COMMAND_MODULE_REC *rec = tmp->data;
|
||||
|
||||
if (g_slist_find(rec->signals, (void *) func) != NULL)
|
||||
return rec;
|
||||
for (tmp2 = rec->callbacks; tmp2 != NULL; tmp2 = tmp2->next) {
|
||||
COMMAND_CALLBACK_REC *cb = tmp2->data;
|
||||
|
||||
if (cb->func == func) {
|
||||
rec->callbacks =
|
||||
g_slist_remove(rec->callbacks, cb);
|
||||
return rec;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
|
@ -131,11 +138,13 @@ command_module_get(COMMAND_REC *rec, const char *module, int protocol)
|
|||
return modrec;
|
||||
}
|
||||
|
||||
void command_bind_to(const char *module, int pos, const char *cmd,
|
||||
int protocol, const char *category, SIGNAL_FUNC func)
|
||||
void command_bind_full(const char *module, int priority, const char *cmd,
|
||||
int protocol, const char *category, SIGNAL_FUNC func,
|
||||
void *user_data)
|
||||
{
|
||||
COMMAND_REC *rec;
|
||||
COMMAND_MODULE_REC *modrec;
|
||||
COMMAND_MODULE_REC *modrec;
|
||||
COMMAND_CALLBACK_REC *cb;
|
||||
char *str;
|
||||
|
||||
g_return_if_fail(module != NULL);
|
||||
|
|
@ -150,11 +159,14 @@ void command_bind_to(const char *module, int pos, const char *cmd,
|
|||
}
|
||||
modrec = command_module_get(rec, module, protocol);
|
||||
|
||||
modrec->signals = g_slist_append(modrec->signals, (void *) func);
|
||||
cb = g_new0(COMMAND_CALLBACK_REC, 1);
|
||||
cb->func = func;
|
||||
cb->user_data = user_data;
|
||||
modrec->callbacks = g_slist_append(modrec->callbacks, cb);
|
||||
|
||||
if (func != NULL) {
|
||||
str = g_strconcat("command ", cmd, NULL);
|
||||
signal_add_full(module, pos, str, func, NULL);
|
||||
signal_add_full(module, priority, str, func, user_data);
|
||||
g_free(str);
|
||||
}
|
||||
|
||||
|
|
@ -176,7 +188,8 @@ static void command_module_free(COMMAND_MODULE_REC *modrec, COMMAND_REC *rec)
|
|||
{
|
||||
rec->modules = g_slist_remove(rec->modules, modrec);
|
||||
|
||||
g_slist_free(modrec->signals);
|
||||
g_slist_foreach(modrec->callbacks, (GFunc) g_free, NULL);
|
||||
g_slist_free(modrec->callbacks);
|
||||
g_free(modrec->name);
|
||||
g_free_not_null(modrec->options);
|
||||
g_free(modrec);
|
||||
|
|
@ -196,7 +209,7 @@ static void command_module_destroy(COMMAND_REC *rec,
|
|||
for (tmp = rec->modules; tmp != NULL; tmp = tmp->next) {
|
||||
COMMAND_MODULE_REC *rec = tmp->data;
|
||||
|
||||
if (rec->signals == NULL)
|
||||
if (rec->callbacks == NULL)
|
||||
freelist = g_slist_append(freelist, rec);
|
||||
else {
|
||||
g_slist_free(freelist);
|
||||
|
|
@ -212,10 +225,10 @@ static void command_module_destroy(COMMAND_REC *rec,
|
|||
command_free(rec);
|
||||
}
|
||||
|
||||
void command_unbind(const char *cmd, SIGNAL_FUNC func)
|
||||
void command_unbind_full(const char *cmd, SIGNAL_FUNC func, void *user_data)
|
||||
{
|
||||
COMMAND_REC *rec;
|
||||
COMMAND_MODULE_REC *modrec;
|
||||
COMMAND_MODULE_REC *modrec;
|
||||
char *str;
|
||||
|
||||
g_return_if_fail(cmd != NULL);
|
||||
|
|
@ -223,17 +236,15 @@ void command_unbind(const char *cmd, SIGNAL_FUNC func)
|
|||
|
||||
rec = command_find(cmd);
|
||||
if (rec != NULL) {
|
||||
modrec = command_module_find_func(rec, func);
|
||||
modrec = command_module_find_and_remove(rec, func);
|
||||
g_return_if_fail(modrec != NULL);
|
||||
|
||||
modrec->signals =
|
||||
g_slist_remove(modrec->signals, (void *) func);
|
||||
if (modrec->signals == NULL)
|
||||
if (modrec->callbacks == NULL)
|
||||
command_module_destroy(rec, modrec);
|
||||
}
|
||||
|
||||
str = g_strconcat("command ", cmd, NULL);
|
||||
signal_remove(str, func);
|
||||
signal_remove_data(str, func, user_data);
|
||||
g_free(str);
|
||||
}
|
||||
|
||||
|
|
@ -767,10 +778,11 @@ static void command_module_unbind_all(COMMAND_REC *rec,
|
|||
{
|
||||
GSList *tmp, *next;
|
||||
|
||||
for (tmp = modrec->signals; tmp != NULL; tmp = next) {
|
||||
for (tmp = modrec->callbacks; tmp != NULL; tmp = next) {
|
||||
COMMAND_CALLBACK_REC *cb = tmp->data;
|
||||
next = tmp->next;
|
||||
|
||||
command_unbind(rec->cmd, (SIGNAL_FUNC) tmp->data);
|
||||
command_unbind_full(rec->cmd, cb->func, cb->user_data);
|
||||
}
|
||||
|
||||
if (g_slist_find(commands, rec) != NULL) {
|
||||
|
|
|
|||
|
|
@ -3,11 +3,16 @@
|
|||
|
||||
#include "signals.h"
|
||||
|
||||
typedef struct {
|
||||
SIGNAL_FUNC func;
|
||||
void *user_data;
|
||||
} COMMAND_CALLBACK_REC;
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
char *options;
|
||||
int protocol; /* chat protocol required for this command */
|
||||
GSList *signals;
|
||||
GSList *callbacks;
|
||||
} COMMAND_MODULE_REC;
|
||||
|
||||
typedef struct {
|
||||
|
|
@ -57,17 +62,23 @@ extern GSList *commands;
|
|||
extern char *current_command; /* the command we're right now. */
|
||||
|
||||
/* Bind command to specified function. */
|
||||
void command_bind_to(const char *module, int pos, const char *cmd,
|
||||
int protocol, const char *category, SIGNAL_FUNC func);
|
||||
#define command_bind(a, b, c) command_bind_to(MODULE_NAME, 1, a, -1, b, c)
|
||||
#define command_bind_first(a, b, c) command_bind_to(MODULE_NAME, 0, a, -1, b, c)
|
||||
#define command_bind_last(a, b, c) command_bind_to(MODULE_NAME, 2, a, -1, b, c)
|
||||
void command_bind_full(const char *module, int priority, const char *cmd,
|
||||
int protocol, const char *category, SIGNAL_FUNC func,
|
||||
void *user_data);
|
||||
#define command_bind(a, b, c) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_DEFAULT, a, -1, b, c, NULL)
|
||||
#define command_bind_first(a, b, c) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_HIGH, a, -1, b, c, NULL)
|
||||
#define command_bind_last(a, b, c) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_LOW, a, -1, b, c, NULL)
|
||||
|
||||
#define command_bind_proto(a, b, c, d) command_bind_to(MODULE_NAME, 1, a, b, c, d)
|
||||
#define command_bind_proto_first(a, b, c, d) command_bind_to(MODULE_NAME, 0, a, b, c, d)
|
||||
#define command_bind_proto_last(a, b, c, d) command_bind_to(MODULE_NAME, 2, a, b, c, d)
|
||||
#define command_bind_data(a, b, c, d) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_DEFAULT, a, -1, b, c, d)
|
||||
#define command_bind_data_first(a, b, c, d) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_HIGH, a, -1, b, c, d)
|
||||
#define command_bind_data_last(a, b, c, d) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_LOW, a, -1, b, c, d)
|
||||
|
||||
void command_unbind(const char *cmd, SIGNAL_FUNC func);
|
||||
#define command_bind_proto(a, b, c, d) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_DEFAULT, a, b, c, d, NULL)
|
||||
#define command_bind_proto_first(a, b, c, d) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_HIGH, a, b, c, d, NULL)
|
||||
#define command_bind_proto_last(a, b, c, d) command_bind_full(MODULE_NAME, SIGNAL_PRIORITY_LOW, a, b, c, d, NULL)
|
||||
|
||||
void command_unbind_full(const char *cmd, SIGNAL_FUNC func, void *user_data);
|
||||
#define command_unbind(cmd, func) command_unbind_full(cmd, func, NULL)
|
||||
|
||||
/* Run subcommand, `cmd' contains the base command, first word in `data'
|
||||
contains the subcommand */
|
||||
|
|
|
|||
|
|
@ -179,8 +179,8 @@ void expando_bind(const char *key, int funccount, SIGNAL_FUNC *funcs)
|
|||
func = arg < funccount ? funcs[arg] : NULL;
|
||||
if (func == NULL) func = funcs[EXPANDO_ARG_NONE];
|
||||
|
||||
signal_add_full_id(MODULE_NAME, 1, rec->signal_ids[n],
|
||||
func, NULL);
|
||||
signal_add_full_id(MODULE_NAME, SIGNAL_PRIORITY_DEFAULT,
|
||||
rec->signal_ids[n], func, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue