Mercurial > audlegacy
annotate src/audacious/hook.c @ 3016:e84073b61ba5 trunk
fix tinyplayer skin
| author | Tomasz Mon <desowin@gmail.com> |
|---|---|
| date | Mon, 09 Jul 2007 13:02:50 +0200 |
| parents | d226b83fa329 |
| children | 4c758281fe8f |
| rev | line source |
|---|---|
|
2865
d226b83fa329
BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents:
2457
diff
changeset
|
1 /* |
|
d226b83fa329
BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents:
2457
diff
changeset
|
2 * audacious: Cross-platform multimedia player. |
|
d226b83fa329
BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents:
2457
diff
changeset
|
3 * hook.c: Hooking. |
|
d226b83fa329
BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents:
2457
diff
changeset
|
4 * |
|
d226b83fa329
BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents:
2457
diff
changeset
|
5 * Copyright (c) 2006-2007 William Pitcock |
| 2404 | 6 * |
|
2865
d226b83fa329
BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents:
2457
diff
changeset
|
7 * Redistribution and use in source and binary forms, with or without |
|
d226b83fa329
BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents:
2457
diff
changeset
|
8 * modification, are permitted provided that the following conditions are |
|
d226b83fa329
BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents:
2457
diff
changeset
|
9 * met: |
|
d226b83fa329
BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents:
2457
diff
changeset
|
10 * |
|
d226b83fa329
BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents:
2457
diff
changeset
|
11 * 1. Redistributions of source code must retain the above copyright notice, |
|
d226b83fa329
BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents:
2457
diff
changeset
|
12 * this list of conditions and the following disclaimer. |
| 2404 | 13 * |
|
2865
d226b83fa329
BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents:
2457
diff
changeset
|
14 * 2. Redistributions in binary form must reproduce the above copyright |
|
d226b83fa329
BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents:
2457
diff
changeset
|
15 * notice, this list of conditions and the following disclaimer in the |
|
d226b83fa329
BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents:
2457
diff
changeset
|
16 * documentation and/or other materials provided with the distribution. |
|
d226b83fa329
BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents:
2457
diff
changeset
|
17 * |
|
d226b83fa329
BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents:
2457
diff
changeset
|
18 * 3. The name of the author may not be used to endorse or promote products |
|
d226b83fa329
BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents:
2457
diff
changeset
|
19 * derived from this software without specific prior written permission. |
| 2404 | 20 * |
|
2865
d226b83fa329
BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents:
2457
diff
changeset
|
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
|
d226b83fa329
BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents:
2457
diff
changeset
|
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
d226b83fa329
BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents:
2457
diff
changeset
|
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
d226b83fa329
BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents:
2457
diff
changeset
|
24 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, |
|
d226b83fa329
BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents:
2457
diff
changeset
|
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|
d226b83fa329
BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents:
2457
diff
changeset
|
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
|
d226b83fa329
BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents:
2457
diff
changeset
|
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
d226b83fa329
BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents:
2457
diff
changeset
|
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|
d226b83fa329
BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents:
2457
diff
changeset
|
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
|
d226b83fa329
BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents:
2457
diff
changeset
|
30 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
d226b83fa329
BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents:
2457
diff
changeset
|
31 * POSSIBILITY OF SUCH DAMAGE. |
| 2404 | 32 */ |
| 33 | |
| 34 #include <glib.h> | |
| 35 #include "hook.h" | |
| 36 | |
| 37 static GSList *hook_list; | |
| 38 | |
| 39 static Hook * | |
| 40 hook_find(const gchar *name) | |
| 41 { | |
| 42 GSList *list; | |
| 43 | |
| 44 for (list = hook_list; list != NULL; list = g_slist_next(list)) | |
| 45 { | |
| 46 Hook *hook = (Hook *) list->data; | |
| 47 | |
| 48 if (!g_ascii_strcasecmp(hook->name, name)) | |
| 49 return hook; | |
| 50 } | |
| 51 | |
| 52 return NULL; | |
| 53 } | |
| 54 | |
| 55 void | |
| 56 hook_register(const gchar *name) | |
| 57 { | |
| 58 Hook *hook; | |
| 59 | |
| 60 g_return_if_fail(name != NULL); | |
| 61 | |
| 62 if ((hook = hook_find(name)) != NULL) | |
| 63 return; | |
| 64 | |
| 65 hook = g_new0(Hook, 1); | |
| 66 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
|
67 hook->items = NULL; |
| 2404 | 68 |
| 69 hook_list = g_slist_append(hook_list, hook); | |
| 70 } | |
| 71 | |
|
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
72 gint |
|
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
73 hook_associate(const gchar *name, HookFunction func, gpointer user_data) |
| 2404 | 74 { |
| 75 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
|
76 HookItem *hookitem; |
| 2404 | 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 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
|
79 g_return_val_if_fail(func != NULL, -1); |
| 2404 | 80 |
| 81 hook = hook_find(name); | |
| 82 | |
| 83 if (hook == NULL) | |
|
2406
6f4094cc3859
[svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents:
2404
diff
changeset
|
84 { |
|
6f4094cc3859
[svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents:
2404
diff
changeset
|
85 hook_register(name); |
|
6f4094cc3859
[svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents:
2404
diff
changeset
|
86 hook = hook_find(name); |
|
6f4094cc3859
[svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents:
2404
diff
changeset
|
87 } |
|
6f4094cc3859
[svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents:
2404
diff
changeset
|
88 |
|
6f4094cc3859
[svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents:
2404
diff
changeset
|
89 /* 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
|
90 g_return_val_if_fail(hook != NULL, -1); |
| 2404 | 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 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
|
93 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
|
94 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
|
95 |
|
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
96 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
|
97 return 0; |
| 2404 | 98 } |
| 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 gint |
| 2404 | 101 hook_dissociate(const gchar *name, HookFunction func) |
| 102 { | |
| 103 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
|
104 GSList *iter; |
| 2404 | 105 |
|
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
106 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
|
107 g_return_val_if_fail(func != NULL, -1); |
| 2404 | 108 |
| 109 hook = hook_find(name); | |
| 110 | |
| 111 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
|
112 return -1; |
| 2404 | 113 |
|
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
114 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
|
115 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
|
116 { |
|
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
117 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
|
118 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
|
119 { |
|
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
120 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
|
121 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
|
122 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
|
123 } |
|
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
124 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
|
125 } |
|
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
126 return -1; |
| 2404 | 127 } |
| 128 | |
| 129 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
|
130 hook_call(const gchar *name, gpointer hook_data) |
| 2404 | 131 { |
| 132 Hook *hook; | |
| 133 GSList *iter; | |
| 134 | |
| 135 g_return_if_fail(name != NULL); | |
| 136 | |
| 137 hook = hook_find(name); | |
| 138 | |
| 139 if (hook == NULL) | |
| 140 return; | |
| 141 | |
|
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
142 for (iter = hook->items; iter != NULL; iter = g_slist_next(iter)) |
| 2404 | 143 { |
|
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
144 HookItem *hookitem = (HookItem*)iter->data; |
| 2404 | 145 |
|
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
146 g_return_if_fail(hookitem->func != NULL); |
| 2404 | 147 |
|
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
148 hookitem->func(hook_data, hookitem->user_data); |
| 2404 | 149 } |
| 150 } |
