# HG changeset patch # User nenolod # Date 1169785396 28800 # Node ID 60f1bc20c19c56aed2aefb665de2f8c056d84942 # Parent 55f92225cd20156a217342e6430a817b44cd9d48 [svn] - hooking implementation. example: hook_register("playback begin"); hook_call("playback begin", ); diff -r 55f92225cd20 -r 60f1bc20c19c ChangeLog --- a/ChangeLog Thu Jan 25 08:19:54 2007 -0800 +++ b/ChangeLog Thu Jan 25 20:23:16 2007 -0800 @@ -1,3 +1,10 @@ +2007-01-25 16:19:54 +0000 Alexandr Orlov + revision [3816] + Update russian translation + trunk/po/ru.po | 36 ++++-------------------------------- + 1 file changed, 4 insertions(+), 32 deletions(-) + + 2007-01-25 14:56:12 +0000 Michael Farber <01mf02@gmail.com> revision [3814] recoded gtk2 style file opener diff -r 55f92225cd20 -r 60f1bc20c19c src/audacious/Makefile --- a/src/audacious/Makefile Thu Jan 25 08:19:54 2007 -0800 +++ b/src/audacious/Makefile Thu Jan 25 20:23:16 2007 -0800 @@ -30,6 +30,7 @@ HEADERS = \ i18n.h \ input.h \ + hook.h \ main.h \ output.h \ playlist.h \ @@ -56,6 +57,7 @@ getopt.c \ glade.c \ hints.c \ + hook.c \ iir.c \ iir_cfs.c \ iir_fpu.c \ diff -r 55f92225cd20 -r 60f1bc20c19c src/audacious/hook.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/audacious/hook.c Thu Jan 25 20:23:16 2007 -0800 @@ -0,0 +1,108 @@ +/* Audacious + * Copyright (c) 2006-2007 William Pitcock + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; under version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include "hook.h" + +static GSList *hook_list; + +static Hook * +hook_find(const gchar *name) +{ + GSList *list; + + for (list = hook_list; list != NULL; list = g_slist_next(list)) + { + Hook *hook = (Hook *) list->data; + + if (!g_ascii_strcasecmp(hook->name, name)) + return hook; + } + + return NULL; +} + +void +hook_register(const gchar *name) +{ + Hook *hook; + + g_return_if_fail(name != NULL); + + if ((hook = hook_find(name)) != NULL) + return; + + hook = g_new0(Hook, 1); + hook->name = g_strdup(name); + + hook_list = g_slist_append(hook_list, hook); +} + +void +hook_associate(const gchar *name, HookFunction func) +{ + Hook *hook; + + g_return_if_fail(name != NULL); + g_return_if_fail(func != NULL); + + hook = hook_find(name); + + if (hook == NULL) + return; + + hook->funcs = g_slist_append(hook->funcs, func); +} + +void +hook_dissociate(const gchar *name, HookFunction func) +{ + Hook *hook; + + g_return_if_fail(name != NULL); + g_return_if_fail(func != NULL); + + hook = hook_find(name); + + if (hook == NULL) + return; + + hook->funcs = g_slist_remove(hook->funcs, func); +} + +void +hook_call(const gchar *name, gpointer user_data) +{ + Hook *hook; + GSList *iter; + + g_return_if_fail(name != NULL); + + hook = hook_find(name); + + if (hook == NULL) + return; + + for (iter = hook->funcs; iter != NULL; iter = g_slist_next(iter)) + { + HookFunction func = (HookFunction) iter->data; + + g_return_if_fail(func != NULL); + + func(user_data); + } +} diff -r 55f92225cd20 -r 60f1bc20c19c src/audacious/hook.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/audacious/hook.h Thu Jan 25 20:23:16 2007 -0800 @@ -0,0 +1,33 @@ +/* Audacious + * Copyright (c) 2006-2007 William Pitcock + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; under version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef __AUDACIOUS_HOOK_H__ +#define __AUDACIOUS_HOOK_H__ + +typedef void (*HookFunction)(gpointer user_data); + +typedef struct { + const gchar *name; + GSList *funcs; +} Hook; + +void hook_register(const gchar *name); +void hook_associate(const gchar *name, HookFunction func); +void hook_dissociate(const gchar *name, HookFunction func); +void hook_call(const gchar *name, gpointer user_data); + +#endif