Mercurial > audlegacy
annotate src/audacious/hook.c @ 2731:f4a5f8fa3836 trunk
[svn] Added stubs in audctrl.c for the unimplemented functions defined in audctrl.h.
Fixed audtool by moving all the DBus methods defined in objects.xml to a common interface; this will be decentralized for MPRIS.
Modified the Makefile so that libaudclient is built after audacious to eliminates a build warning.
author | magma |
---|---|
date | Fri, 11 May 2007 01:42:32 -0700 |
parents | b7f77224ea03 |
children | d226b83fa329 |
rev | line source |
---|---|
2404 | 1 /* Audacious |
2 * Copyright (c) 2006-2007 William Pitcock | |
3 * | |
4 * This program is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; under version 2 of the License. | |
7 * | |
8 * This program is distributed in the hope that it will be useful, | |
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 * GNU General Public License for more details. | |
12 * | |
13 * You should have received a copy of the GNU General Public License | |
14 * along with this program; if not, write to the Free Software | |
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
16 */ | |
17 | |
18 #include <glib.h> | |
19 #include "hook.h" | |
20 | |
21 static GSList *hook_list; | |
22 | |
23 static Hook * | |
24 hook_find(const gchar *name) | |
25 { | |
26 GSList *list; | |
27 | |
28 for (list = hook_list; list != NULL; list = g_slist_next(list)) | |
29 { | |
30 Hook *hook = (Hook *) list->data; | |
31 | |
32 if (!g_ascii_strcasecmp(hook->name, name)) | |
33 return hook; | |
34 } | |
35 | |
36 return NULL; | |
37 } | |
38 | |
39 void | |
40 hook_register(const gchar *name) | |
41 { | |
42 Hook *hook; | |
43 | |
44 g_return_if_fail(name != NULL); | |
45 | |
46 if ((hook = hook_find(name)) != NULL) | |
47 return; | |
48 | |
49 hook = g_new0(Hook, 1); | |
50 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
|
51 hook->items = NULL; |
2404 | 52 |
53 hook_list = g_slist_append(hook_list, hook); | |
54 } | |
55 | |
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
56 gint |
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
57 hook_associate(const gchar *name, HookFunction func, gpointer user_data) |
2404 | 58 { |
59 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
|
60 HookItem *hookitem; |
2404 | 61 |
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 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
|
63 g_return_val_if_fail(func != NULL, -1); |
2404 | 64 |
65 hook = hook_find(name); | |
66 | |
67 if (hook == NULL) | |
2406
6f4094cc3859
[svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents:
2404
diff
changeset
|
68 { |
6f4094cc3859
[svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents:
2404
diff
changeset
|
69 hook_register(name); |
6f4094cc3859
[svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents:
2404
diff
changeset
|
70 hook = hook_find(name); |
6f4094cc3859
[svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents:
2404
diff
changeset
|
71 } |
6f4094cc3859
[svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents:
2404
diff
changeset
|
72 |
6f4094cc3859
[svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents:
2404
diff
changeset
|
73 /* 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
|
74 g_return_val_if_fail(hook != NULL, -1); |
2404 | 75 |
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 = 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
|
77 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
|
78 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
|
79 |
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
80 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
|
81 return 0; |
2404 | 82 } |
83 | |
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
84 gint |
2404 | 85 hook_dissociate(const gchar *name, HookFunction func) |
86 { | |
87 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
|
88 GSList *iter; |
2404 | 89 |
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(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
|
91 g_return_val_if_fail(func != NULL, -1); |
2404 | 92 |
93 hook = hook_find(name); | |
94 | |
95 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
|
96 return -1; |
2404 | 97 |
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 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
|
99 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
|
100 { |
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
101 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
|
102 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
|
103 { |
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
104 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
|
105 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
|
106 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
|
107 } |
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
108 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
|
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 return -1; |
2404 | 111 } |
112 | |
113 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
|
114 hook_call(const gchar *name, gpointer hook_data) |
2404 | 115 { |
116 Hook *hook; | |
117 GSList *iter; | |
118 | |
119 g_return_if_fail(name != NULL); | |
120 | |
121 hook = hook_find(name); | |
122 | |
123 if (hook == NULL) | |
124 return; | |
125 | |
2457
b7f77224ea03
[svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents:
2406
diff
changeset
|
126 for (iter = hook->items; iter != NULL; iter = g_slist_next(iter)) |
2404 | 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 HookItem *hookitem = (HookItem*)iter->data; |
2404 | 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 g_return_if_fail(hookitem->func != NULL); |
2404 | 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 hookitem->func(hook_data, hookitem->user_data); |
2404 | 133 } |
134 } |