Mercurial > audlegacy
annotate audacious/pluginenum.c @ 1592:752949e9aec4 trunk
[svn] Actually cast variables to glib types before feeding them into glib compare functions. Resolves another 16 signedness warnings on PPC.
author | chainsaw |
---|---|
date | Thu, 24 Aug 2006 12:23:54 -0700 |
parents | e513069caf71 |
children | 20ff61083530 |
rev | line source |
---|---|
0 | 1 /* BMP - Cross-platform multimedia player |
2 * Copyright (C) 2003-2004 BMP development team. | |
3 * | |
4 * Based on XMMS: | |
5 * Copyright (C) 1998-2003 XMMS development team. | |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
1460 | 8 * it under the terms of the GNU General Public License as published by |
0 | 9 * the Free Software Foundation; either version 2 of the License, or |
10 * (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 * GNU General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
1459 | 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
0 | 20 */ |
21 | |
22 #ifdef HAVE_CONFIG_H | |
23 # include "config.h" | |
24 #endif | |
25 | |
26 #include "pluginenum.h" | |
27 | |
28 #include <glib.h> | |
29 #include <gmodule.h> | |
30 #include <glib/gprintf.h> | |
31 #include <string.h> | |
32 | |
33 #include "controlsocket.h" | |
34 #include "main.h" | |
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
687
diff
changeset
|
35 #include "mainwin.h" |
538
e4e897d20791
[svn] remove libaudcore, we never did anything with it
nenolod
parents:
380
diff
changeset
|
36 #include "playback.h" |
0 | 37 #include "playlist.h" |
38 #include "util.h" | |
39 | |
40 #include "effect.h" | |
41 #include "general.h" | |
42 #include "input.h" | |
43 #include "output.h" | |
44 #include "visualization.h" | |
45 | |
46 const gchar *plugin_dir_list[] = { | |
47 PLUGINSUBS, | |
48 NULL | |
49 }; | |
50 | |
51 GHashTable *plugin_matrix = NULL; | |
1563 | 52 GList *lowlevel_list = NULL; |
0 | 53 |
54 static gint | |
55 inputlist_compare_func(gconstpointer a, gconstpointer b) | |
56 { | |
57 const InputPlugin *ap = a, *bp = b; | |
58 return strcasecmp(ap->description, bp->description); | |
59 } | |
60 | |
61 static gint | |
62 outputlist_compare_func(gconstpointer a, gconstpointer b) | |
63 { | |
64 const OutputPlugin *ap = a, *bp = b; | |
65 return strcasecmp(ap->description, bp->description); | |
66 } | |
67 | |
68 static gint | |
69 effectlist_compare_func(gconstpointer a, gconstpointer b) | |
70 { | |
71 const EffectPlugin *ap = a, *bp = b; | |
72 return strcasecmp(ap->description, bp->description); | |
73 } | |
74 | |
75 static gint | |
76 generallist_compare_func(gconstpointer a, gconstpointer b) | |
77 { | |
78 const GeneralPlugin *ap = a, *bp = b; | |
79 return strcasecmp(ap->description, bp->description); | |
80 } | |
81 | |
82 static gint | |
83 vislist_compare_func(gconstpointer a, gconstpointer b) | |
84 { | |
85 const VisPlugin *ap = a, *bp = b; | |
86 return strcasecmp(ap->description, bp->description); | |
87 } | |
88 | |
89 static gboolean | |
90 plugin_is_duplicate(const gchar * filename) | |
91 { | |
92 GList *l; | |
93 const gchar *basename = g_basename(filename); | |
94 | |
95 /* FIXME: messy stuff */ | |
96 | |
97 for (l = ip_data.input_list; l; l = g_list_next(l)) | |
98 if (!strcmp(basename, g_basename(INPUT_PLUGIN(l->data)->filename))) | |
99 return TRUE; | |
100 | |
101 for (l = op_data.output_list; l; l = g_list_next(l)) | |
102 if (!strcmp(basename, g_basename(OUTPUT_PLUGIN(l->data)->filename))) | |
103 return TRUE; | |
104 | |
105 for (l = ep_data.effect_list; l; l = g_list_next(l)) | |
106 if (!strcmp(basename, g_basename(EFFECT_PLUGIN(l->data)->filename))) | |
107 return TRUE; | |
108 | |
109 for (l = gp_data.general_list; l; l = g_list_next(l)) | |
110 if (!strcmp(basename, g_basename(GENERAL_PLUGIN(l->data)->filename))) | |
111 return TRUE; | |
112 | |
113 for (l = vp_data.vis_list; l; l = g_list_next(l)) | |
114 if (!strcmp(basename, g_basename(VIS_PLUGIN(l->data)->filename))) | |
115 return TRUE; | |
116 | |
1563 | 117 for (l = lowlevel_list; l; l = g_list_next(l)) |
118 if (!strcmp(basename, g_basename(VIS_PLUGIN(l->data)->filename))) | |
119 return TRUE; | |
120 | |
0 | 121 return FALSE; |
122 } | |
123 | |
124 | |
125 #define PLUGIN_GET_INFO(x) ((PluginGetInfoFunc)(x))() | |
126 typedef Plugin * (*PluginGetInfoFunc) (void); | |
127 | |
128 static void | |
129 input_plugin_init(Plugin * plugin) | |
130 { | |
131 InputPlugin *p = INPUT_PLUGIN(plugin); | |
132 | |
133 p->get_vis_type = input_get_vis_type; | |
134 p->add_vis_pcm = input_add_vis_pcm; | |
135 | |
136 /* Pretty const casts courtesy of XMMS's plugin.h legacy. Anyone | |
137 else thinks we could use a CONST macro to solve the warnings? | |
138 - descender */ | |
139 p->set_info = (void (*)(gchar *, gint, gint, gint, gint)) playlist_set_info; | |
140 p->set_info_text = (void (*)(gchar *)) input_set_info_text; | |
1273
3b990c26fc46
[svn] - Support for the buffer indicator in playpaus.png that was apparently
nhjm449
parents:
906
diff
changeset
|
141 p->set_status_buffering = (void (*)(gboolean)) input_set_status_buffering; |
3b990c26fc46
[svn] - Support for the buffer indicator in playpaus.png that was apparently
nhjm449
parents:
906
diff
changeset
|
142 |
0 | 143 ip_data.input_list = g_list_append(ip_data.input_list, p); |
144 | |
145 g_hash_table_replace(plugin_matrix, g_path_get_basename(p->filename), | |
146 GINT_TO_POINTER(1)); | |
147 } | |
148 | |
149 static void | |
150 output_plugin_init(Plugin * plugin) | |
151 { | |
152 OutputPlugin *p = OUTPUT_PLUGIN(plugin); | |
153 op_data.output_list = g_list_append(op_data.output_list, p); | |
154 } | |
155 | |
156 static void | |
157 effect_plugin_init(Plugin * plugin) | |
158 { | |
159 EffectPlugin *p = EFFECT_PLUGIN(plugin); | |
160 ep_data.effect_list = g_list_append(ep_data.effect_list, p); | |
161 } | |
162 | |
163 static void | |
164 general_plugin_init(Plugin * plugin) | |
165 { | |
166 GeneralPlugin *p = GENERAL_PLUGIN(plugin); | |
167 p->xmms_session = ctrlsocket_get_session_id(); | |
168 gp_data.general_list = g_list_append(gp_data.general_list, p); | |
169 } | |
170 | |
171 static void | |
172 vis_plugin_init(Plugin * plugin) | |
173 { | |
174 VisPlugin *p = VIS_PLUGIN(plugin); | |
175 p->xmms_session = ctrlsocket_get_session_id(); | |
176 p->disable_plugin = vis_disable_plugin; | |
177 vp_data.vis_list = g_list_append(vp_data.vis_list, p); | |
178 } | |
179 | |
1563 | 180 static void |
181 lowlevel_plugin_init(Plugin * plugin) | |
182 { | |
183 LowlevelPlugin *p = LOWLEVEL_PLUGIN(plugin); | |
184 lowlevel_list = g_list_append(lowlevel_list, p); | |
185 } | |
0 | 186 |
187 /* FIXME: Placed here (hopefully) temporarily - descender */ | |
188 | |
189 typedef struct { | |
190 const gchar *name; | |
191 const gchar *id; | |
192 void (*init)(Plugin *); | |
193 } PluginType; | |
194 | |
195 static PluginType plugin_types[] = { | |
196 { "input" , "get_iplugin_info", input_plugin_init }, | |
197 { "output" , "get_oplugin_info", output_plugin_init }, | |
198 { "effect" , "get_eplugin_info", effect_plugin_init }, | |
199 { "general" , "get_gplugin_info", general_plugin_init }, | |
200 { "visualization", "get_vplugin_info", vis_plugin_init }, | |
1563 | 201 { "lowlevel" , "get_lplugin_info", lowlevel_plugin_init }, |
0 | 202 { NULL, NULL, NULL } |
203 }; | |
204 | |
205 static void | |
206 add_plugin(const gchar * filename) | |
207 { | |
208 PluginType *type; | |
209 GModule *module; | |
210 gpointer func; | |
211 | |
212 if (plugin_is_duplicate(filename)) | |
213 return; | |
214 | |
834 | 215 if (!(module = g_module_open(filename, 0))) { |
12 | 216 printf("Failed to load plugin (%s): %s\n", |
0 | 217 filename, g_module_error()); |
218 return; | |
219 } | |
220 | |
221 for (type = plugin_types; type->name; type++) | |
222 { | |
223 if (g_module_symbol(module, type->id, &func)) { | |
224 Plugin *plugin = PLUGIN_GET_INFO(func); | |
225 | |
226 plugin->handle = module; | |
227 plugin->filename = g_strdup(filename); | |
228 type->init(PLUGIN_GET_INFO(func)); | |
229 | |
230 return; | |
231 } | |
232 } | |
233 | |
12 | 234 printf("Invalid plugin (%s)\n", filename); |
0 | 235 g_module_close(module); |
236 } | |
237 | |
238 static gboolean | |
239 scan_plugin_func(const gchar * path, const gchar * basename, gpointer data) | |
240 { | |
241 if (!str_has_suffix_nocase(basename, G_MODULE_SUFFIX)) | |
242 return FALSE; | |
243 | |
244 if (!g_file_test(path, G_FILE_TEST_IS_REGULAR)) | |
245 return FALSE; | |
246 | |
247 add_plugin(path); | |
248 | |
249 return FALSE; | |
250 } | |
251 | |
252 static void | |
253 scan_plugins(const gchar * path) | |
254 { | |
255 dir_foreach(path, scan_plugin_func, NULL, NULL); | |
256 } | |
257 | |
258 void | |
259 plugin_system_init(void) | |
260 { | |
261 gchar *dir, **disabled; | |
262 GList *node; | |
263 OutputPlugin *op; | |
264 InputPlugin *ip; | |
1566 | 265 LowlevelPlugin *lp; |
0 | 266 gint dirsel = 0, i = 0; |
267 | |
268 if (!g_module_supported()) { | |
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
687
diff
changeset
|
269 report_error("Module loading not supported! Plugins will not be loaded.\n"); |
0 | 270 return; |
271 } | |
272 | |
273 plugin_matrix = g_hash_table_new_full(g_str_hash, g_int_equal, g_free, | |
274 NULL); | |
275 | |
276 #ifndef DISABLE_USER_PLUGIN_DIR | |
277 scan_plugins(bmp_paths[BMP_PATH_USER_PLUGIN_DIR]); | |
278 /* | |
279 * This is in a separate loop so if the user puts them in the | |
280 * wrong dir we'll still get them in the right order (home dir | |
281 * first) - Zinx | |
282 */ | |
283 while (plugin_dir_list[dirsel]) { | |
284 dir = g_build_filename(bmp_paths[BMP_PATH_USER_PLUGIN_DIR], | |
285 plugin_dir_list[dirsel++], NULL); | |
286 scan_plugins(dir); | |
287 g_free(dir); | |
288 } | |
289 dirsel = 0; | |
290 #endif | |
291 | |
292 while (plugin_dir_list[dirsel]) { | |
293 dir = g_build_filename(PLUGIN_DIR, plugin_dir_list[dirsel++], NULL); | |
294 scan_plugins(dir); | |
295 g_free(dir); | |
296 } | |
297 | |
298 op_data.output_list = g_list_sort(op_data.output_list, outputlist_compare_func); | |
299 if (!op_data.current_output_plugin | |
300 && g_list_length(op_data.output_list)) { | |
301 op_data.current_output_plugin = op_data.output_list->data; | |
302 } | |
303 | |
304 ip_data.input_list = g_list_sort(ip_data.input_list, inputlist_compare_func); | |
305 | |
306 ep_data.effect_list = g_list_sort(ep_data.effect_list, effectlist_compare_func); | |
307 ep_data.enabled_list = NULL; | |
308 | |
309 gp_data.general_list = g_list_sort(gp_data.general_list, generallist_compare_func); | |
310 gp_data.enabled_list = NULL; | |
311 | |
312 vp_data.vis_list = g_list_sort(vp_data.vis_list, vislist_compare_func); | |
313 vp_data.enabled_list = NULL; | |
314 | |
315 general_enable_from_stringified_list(cfg.enabled_gplugins); | |
316 vis_enable_from_stringified_list(cfg.enabled_vplugins); | |
317 effect_enable_from_stringified_list(cfg.enabled_eplugins); | |
318 | |
319 g_free(cfg.enabled_gplugins); | |
320 cfg.enabled_gplugins = NULL; | |
321 | |
322 g_free(cfg.enabled_vplugins); | |
323 cfg.enabled_vplugins = NULL; | |
324 | |
325 g_free(cfg.enabled_eplugins); | |
326 cfg.enabled_eplugins = NULL; | |
327 | |
328 for (node = op_data.output_list; node; node = g_list_next(node)) { | |
329 op = OUTPUT_PLUGIN(node->data); | |
330 /* | |
331 * Only test basename to avoid problems when changing | |
332 * prefix. We will only see one plugin with the same | |
333 * basename, so this is usually what the user want. | |
334 */ | |
335 if (!strcmp(g_basename(cfg.outputplugin), g_basename(op->filename))) | |
336 op_data.current_output_plugin = op; | |
337 if (op->init) | |
338 op->init(); | |
339 } | |
340 | |
341 for (node = ip_data.input_list; node; node = g_list_next(node)) { | |
342 ip = INPUT_PLUGIN(node->data); | |
343 if (ip->init) | |
344 ip->init(); | |
345 } | |
346 | |
1566 | 347 for (node = lowlevel_list; node; node = g_list_next(node)) { |
348 lp = LOWLEVEL_PLUGIN(node->data); | |
349 if (lp->init) | |
350 lp->init(); | |
351 } | |
352 | |
0 | 353 if (cfg.disabled_iplugins) { |
354 disabled = g_strsplit(cfg.disabled_iplugins, ":", 0); | |
355 while (disabled[i]) { | |
356 g_hash_table_replace(plugin_matrix, disabled[i], | |
357 GINT_TO_POINTER(FALSE)); | |
358 i++; | |
359 } | |
360 | |
361 g_free(disabled); | |
362 | |
363 g_free(cfg.disabled_iplugins); | |
364 cfg.disabled_iplugins = NULL; | |
365 } | |
366 } | |
367 | |
368 void | |
369 plugin_system_cleanup(void) | |
370 { | |
371 InputPlugin *ip; | |
372 OutputPlugin *op; | |
373 EffectPlugin *ep; | |
374 GeneralPlugin *gp; | |
375 VisPlugin *vp; | |
1563 | 376 LowlevelPlugin *lp; |
0 | 377 GList *node; |
378 | |
379 g_message("Shutting down plugin system"); | |
380 | |
906 | 381 if (bmp_playback_get_playing()) { |
382 ip_data.stop = TRUE; | |
0 | 383 bmp_playback_stop(); |
906 | 384 ip_data.stop = FALSE; |
385 } | |
0 | 386 |
387 for (node = get_input_list(); node; node = g_list_next(node)) { | |
388 ip = INPUT_PLUGIN(node->data); | |
389 if (ip && ip->cleanup) { | |
390 ip->cleanup(); | |
391 GDK_THREADS_LEAVE(); | |
392 while (g_main_iteration(FALSE)); | |
393 GDK_THREADS_ENTER(); | |
394 } | |
395 g_module_close(ip->handle); | |
396 } | |
397 | |
398 if (ip_data.input_list) | |
399 g_list_free(ip_data.input_list); | |
400 | |
401 for (node = get_output_list(); node; node = g_list_next(node)) { | |
402 op = OUTPUT_PLUGIN(node->data); | |
309 | 403 if (op && op->cleanup) { |
404 op->cleanup(); | |
405 GDK_THREADS_LEAVE(); | |
406 while (g_main_iteration(FALSE)); | |
407 GDK_THREADS_ENTER(); | |
408 } | |
0 | 409 g_module_close(op->handle); |
410 } | |
411 | |
412 if (op_data.output_list) | |
413 g_list_free(op_data.output_list); | |
414 | |
415 for (node = get_effect_list(); node; node = g_list_next(node)) { | |
416 ep = EFFECT_PLUGIN(node->data); | |
417 if (ep && ep->cleanup) { | |
418 ep->cleanup(); | |
419 GDK_THREADS_LEAVE(); | |
420 while (g_main_iteration(FALSE)); | |
421 GDK_THREADS_ENTER(); | |
422 } | |
423 g_module_close(ep->handle); | |
424 } | |
425 | |
426 if (ep_data.effect_list) | |
427 g_list_free(ep_data.effect_list); | |
428 | |
429 for (node = get_general_enabled_list(); node; node = g_list_next(node)) { | |
430 gp = GENERAL_PLUGIN(node->data); | |
431 enable_general_plugin(g_list_index(gp_data.general_list, gp), FALSE); | |
432 } | |
433 | |
434 if (gp_data.enabled_list) | |
435 g_list_free(gp_data.enabled_list); | |
436 | |
437 GDK_THREADS_LEAVE(); | |
438 while (g_main_iteration(FALSE)); | |
439 GDK_THREADS_ENTER(); | |
440 | |
441 for (node = get_general_list(); node; node = g_list_next(node)) { | |
442 gp = GENERAL_PLUGIN(node->data); | |
650
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
443 if (gp && gp->cleanup) { |
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
444 gp->cleanup(); |
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
445 GDK_THREADS_LEAVE(); |
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
446 while (g_main_iteration(FALSE)); |
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
447 GDK_THREADS_ENTER(); |
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
448 } |
0 | 449 g_module_close(gp->handle); |
450 } | |
451 | |
452 if (gp_data.general_list) | |
453 g_list_free(gp_data.general_list); | |
454 | |
455 for (node = get_vis_enabled_list(); node; node = g_list_next(node)) { | |
456 vp = VIS_PLUGIN(node->data); | |
457 enable_vis_plugin(g_list_index(vp_data.vis_list, vp), FALSE); | |
458 } | |
459 | |
460 if (vp_data.enabled_list) | |
461 g_list_free(vp_data.enabled_list); | |
462 | |
463 GDK_THREADS_LEAVE(); | |
464 while (g_main_iteration(FALSE)); | |
465 GDK_THREADS_ENTER(); | |
466 | |
467 for (node = get_vis_list(); node; node = g_list_next(node)) { | |
468 vp = VIS_PLUGIN(node->data); | |
650
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
469 if (vp && vp->cleanup) { |
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
470 vp->cleanup(); |
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
471 GDK_THREADS_LEAVE(); |
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
472 while (g_main_iteration(FALSE)); |
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
473 GDK_THREADS_ENTER(); |
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
474 } |
0 | 475 g_module_close(vp->handle); |
476 } | |
477 | |
478 if (vp_data.vis_list) | |
479 g_list_free(vp_data.vis_list); | |
1563 | 480 |
481 for (node = lowlevel_list; node; node = g_list_next(node)) { | |
482 lp = LOWLEVEL_PLUGIN(node->data); | |
483 if (lp && lp->cleanup) { | |
484 lp->cleanup(); | |
485 GDK_THREADS_LEAVE(); | |
486 while (g_main_iteration(FALSE)); | |
487 GDK_THREADS_ENTER(); | |
488 } | |
489 g_module_close(lp->handle); | |
490 } | |
491 | |
492 if (lowlevel_list) | |
493 g_list_free(lowlevel_list); | |
0 | 494 } |