annotate src/audacious/hook.c @ 4304:eb5f10afe3a0

swith to original xmms band frequencies
author Eugene Zagidullin <e.asphyx@gmail.com>
date Sun, 24 Feb 2008 18:35:40 +0300
parents f1c756f39e6c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3112
4c758281fe8f Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents: 2865
diff changeset
1 /* Audacious
4c758281fe8f Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents: 2865
diff changeset
2 * Copyright (c) 2006-2007 William Pitcock
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
3 *
3112
4c758281fe8f Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents: 2865
diff changeset
4 * This program is free software; you can redistribute it and/or modify
4c758281fe8f Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents: 2865
diff changeset
5 * it under the terms of the GNU General Public License as published by
3121
3b6d316f8b09 GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents: 3112
diff changeset
6 * the Free Software Foundation; under version 3 of the License.
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
7 *
3112
4c758281fe8f Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents: 2865
diff changeset
8 * This program is distributed in the hope that it will be useful,
4c758281fe8f Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents: 2865
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4c758281fe8f Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents: 2865
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4c758281fe8f Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents: 2865
diff changeset
11 * GNU General Public License for more details.
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
12 *
3112
4c758281fe8f Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents: 2865
diff changeset
13 * You should have received a copy of the GNU General Public License
3121
3b6d316f8b09 GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents: 3112
diff changeset
14 * along with this program. If not, see <http://www.gnu.org/licenses>.
3123
f1c756f39e6c Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents: 3121
diff changeset
15 *
f1c756f39e6c Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents: 3121
diff changeset
16 * The Audacious team does not consider modular code linking to
f1c756f39e6c Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents: 3121
diff changeset
17 * Audacious or using our public API to be a derived work.
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
18 */
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
19
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
20 #include <glib.h>
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
21 #include "hook.h"
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
22
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
23 static GSList *hook_list;
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
24
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
25 static Hook *
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
26 hook_find(const gchar *name)
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
27 {
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
28 GSList *list;
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
29
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
30 for (list = hook_list; list != NULL; list = g_slist_next(list))
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
31 {
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
32 Hook *hook = (Hook *) list->data;
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
33
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
34 if (!g_ascii_strcasecmp(hook->name, name))
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
35 return hook;
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
36 }
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
37
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
38 return NULL;
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
39 }
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
40
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
41 void
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
42 hook_register(const gchar *name)
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
43 {
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
44 Hook *hook;
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
45
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
46 g_return_if_fail(name != NULL);
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
47
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
48 if ((hook = hook_find(name)) != NULL)
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
49 return;
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
50
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
51 hook = g_new0(Hook, 1);
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
52 hook->name = g_strdup(name);
2457
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
53 hook->items = NULL;
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
54
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
55 hook_list = g_slist_append(hook_list, hook);
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
56 }
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
57
2457
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
58 gint
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
59 hook_associate(const gchar *name, HookFunction func, gpointer user_data)
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
60 {
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
61 Hook *hook;
2457
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
62 HookItem *hookitem;
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
63
2457
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
64 g_return_val_if_fail(name != NULL, -1);
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
65 g_return_val_if_fail(func != NULL, -1);
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
66
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
67 hook = hook_find(name);
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
68
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
69 if (hook == NULL)
2406
6f4094cc3859 [svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents: 2404
diff changeset
70 {
6f4094cc3859 [svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents: 2404
diff changeset
71 hook_register(name);
6f4094cc3859 [svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents: 2404
diff changeset
72 hook = hook_find(name);
6f4094cc3859 [svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents: 2404
diff changeset
73 }
6f4094cc3859 [svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents: 2404
diff changeset
74
6f4094cc3859 [svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents: 2404
diff changeset
75 /* this *cant* happen */
2457
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
76 g_return_val_if_fail(hook != NULL, -1);
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
77
2457
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
78 hookitem = g_new0(HookItem, 1);
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
79 hookitem->func = func;
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
80 hookitem->user_data = user_data;
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
81
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
82 hook->items = g_slist_append(hook->items, hookitem);
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
83 return 0;
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
84 }
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
85
2457
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
86 gint
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
87 hook_dissociate(const gchar *name, HookFunction func)
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
88 {
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
89 Hook *hook;
2457
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
90 GSList *iter;
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
91
2457
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
92 g_return_val_if_fail(name != NULL, -1);
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
93 g_return_val_if_fail(func != NULL, -1);
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
94
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
95 hook = hook_find(name);
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
96
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
97 if (hook == NULL)
2457
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
98 return -1;
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
99
2457
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
100 iter = hook->items;
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
101 while (iter != NULL)
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
102 {
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
103 HookItem *hookitem = (HookItem*)iter->data;
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
104 if (hookitem->func == func)
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
105 {
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
106 hook->items = g_slist_delete_link(hook->items, iter);
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
107 g_free( hookitem );
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
108 return 0;
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
109 }
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
110 iter = g_slist_next(iter);
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
111 }
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
112 return -1;
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
113 }
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
114
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
115 void
2457
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
116 hook_call(const gchar *name, gpointer hook_data)
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
117 {
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
118 Hook *hook;
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
119 GSList *iter;
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
120
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
121 g_return_if_fail(name != NULL);
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
122
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
123 hook = hook_find(name);
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
124
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
125 if (hook == NULL)
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
126 return;
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
127
2457
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
128 for (iter = hook->items; iter != NULL; iter = g_slist_next(iter))
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
129 {
2457
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
130 HookItem *hookitem = (HookItem*)iter->data;
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
131
2457
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
132 g_return_if_fail(hookitem->func != NULL);
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
133
2457
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
134 hookitem->func(hook_data, hookitem->user_data);
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
135 }
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
136 }