Mercurial > audlegacy
annotate audacious/pluginenum.c @ 781:12c47704b4b5 trunk
[svn] Add error reporting for many places, patch by external contributor Derek
Pomery (nemo @ #audacious). Additional cleanups too.
| author | nenolod |
|---|---|
| date | Thu, 02 Mar 2006 08:14:36 -0800 |
| parents | 0a220c3183b8 |
| children | d17d96d91e7d |
| 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 | |
| 8 * it under the terms of the GNU General Public Licensse as published by | |
| 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 | |
| 19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
| 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; | |
| 52 | |
| 53 static gint | |
| 54 inputlist_compare_func(gconstpointer a, gconstpointer b) | |
| 55 { | |
| 56 const InputPlugin *ap = a, *bp = b; | |
| 57 return strcasecmp(ap->description, bp->description); | |
| 58 } | |
| 59 | |
| 60 static gint | |
| 61 outputlist_compare_func(gconstpointer a, gconstpointer b) | |
| 62 { | |
| 63 const OutputPlugin *ap = a, *bp = b; | |
| 64 return strcasecmp(ap->description, bp->description); | |
| 65 } | |
| 66 | |
| 67 static gint | |
| 68 effectlist_compare_func(gconstpointer a, gconstpointer b) | |
| 69 { | |
| 70 const EffectPlugin *ap = a, *bp = b; | |
| 71 return strcasecmp(ap->description, bp->description); | |
| 72 } | |
| 73 | |
| 74 static gint | |
| 75 generallist_compare_func(gconstpointer a, gconstpointer b) | |
| 76 { | |
| 77 const GeneralPlugin *ap = a, *bp = b; | |
| 78 return strcasecmp(ap->description, bp->description); | |
| 79 } | |
| 80 | |
| 81 static gint | |
| 82 vislist_compare_func(gconstpointer a, gconstpointer b) | |
| 83 { | |
| 84 const VisPlugin *ap = a, *bp = b; | |
| 85 return strcasecmp(ap->description, bp->description); | |
| 86 } | |
| 87 | |
| 88 static gboolean | |
| 89 plugin_is_duplicate(const gchar * filename) | |
| 90 { | |
| 91 GList *l; | |
| 92 const gchar *basename = g_basename(filename); | |
| 93 | |
| 94 /* FIXME: messy stuff */ | |
| 95 | |
| 96 for (l = ip_data.input_list; l; l = g_list_next(l)) | |
| 97 if (!strcmp(basename, g_basename(INPUT_PLUGIN(l->data)->filename))) | |
| 98 return TRUE; | |
| 99 | |
| 100 for (l = op_data.output_list; l; l = g_list_next(l)) | |
| 101 if (!strcmp(basename, g_basename(OUTPUT_PLUGIN(l->data)->filename))) | |
| 102 return TRUE; | |
| 103 | |
| 104 for (l = ep_data.effect_list; l; l = g_list_next(l)) | |
| 105 if (!strcmp(basename, g_basename(EFFECT_PLUGIN(l->data)->filename))) | |
| 106 return TRUE; | |
| 107 | |
| 108 for (l = gp_data.general_list; l; l = g_list_next(l)) | |
| 109 if (!strcmp(basename, g_basename(GENERAL_PLUGIN(l->data)->filename))) | |
| 110 return TRUE; | |
| 111 | |
| 112 for (l = vp_data.vis_list; l; l = g_list_next(l)) | |
| 113 if (!strcmp(basename, g_basename(VIS_PLUGIN(l->data)->filename))) | |
| 114 return TRUE; | |
| 115 | |
| 116 return FALSE; | |
| 117 } | |
| 118 | |
| 119 | |
| 120 #define PLUGIN_GET_INFO(x) ((PluginGetInfoFunc)(x))() | |
| 121 typedef Plugin * (*PluginGetInfoFunc) (void); | |
| 122 | |
| 123 static void | |
| 124 input_plugin_init(Plugin * plugin) | |
| 125 { | |
| 126 InputPlugin *p = INPUT_PLUGIN(plugin); | |
| 127 | |
| 128 p->get_vis_type = input_get_vis_type; | |
| 129 p->add_vis_pcm = input_add_vis_pcm; | |
| 130 | |
| 131 /* Pretty const casts courtesy of XMMS's plugin.h legacy. Anyone | |
| 132 else thinks we could use a CONST macro to solve the warnings? | |
| 133 - descender */ | |
| 134 p->set_info = (void (*)(gchar *, gint, gint, gint, gint)) playlist_set_info; | |
| 135 p->set_info_text = (void (*)(gchar *)) input_set_info_text; | |
| 136 | |
| 137 ip_data.input_list = g_list_append(ip_data.input_list, p); | |
| 138 | |
| 139 g_hash_table_replace(plugin_matrix, g_path_get_basename(p->filename), | |
| 140 GINT_TO_POINTER(1)); | |
| 141 } | |
| 142 | |
| 143 static void | |
| 144 output_plugin_init(Plugin * plugin) | |
| 145 { | |
| 146 OutputPlugin *p = OUTPUT_PLUGIN(plugin); | |
| 147 op_data.output_list = g_list_append(op_data.output_list, p); | |
| 148 } | |
| 149 | |
| 150 static void | |
| 151 effect_plugin_init(Plugin * plugin) | |
| 152 { | |
| 153 EffectPlugin *p = EFFECT_PLUGIN(plugin); | |
| 154 ep_data.effect_list = g_list_append(ep_data.effect_list, p); | |
| 155 } | |
| 156 | |
| 157 static void | |
| 158 general_plugin_init(Plugin * plugin) | |
| 159 { | |
| 160 GeneralPlugin *p = GENERAL_PLUGIN(plugin); | |
| 161 p->xmms_session = ctrlsocket_get_session_id(); | |
| 162 gp_data.general_list = g_list_append(gp_data.general_list, p); | |
| 163 } | |
| 164 | |
| 165 static void | |
| 166 vis_plugin_init(Plugin * plugin) | |
| 167 { | |
| 168 VisPlugin *p = VIS_PLUGIN(plugin); | |
| 169 p->xmms_session = ctrlsocket_get_session_id(); | |
| 170 p->disable_plugin = vis_disable_plugin; | |
| 171 vp_data.vis_list = g_list_append(vp_data.vis_list, p); | |
| 172 } | |
| 173 | |
| 174 | |
| 175 /* FIXME: Placed here (hopefully) temporarily - descender */ | |
| 176 | |
| 177 typedef struct { | |
| 178 const gchar *name; | |
| 179 const gchar *id; | |
| 180 void (*init)(Plugin *); | |
| 181 } PluginType; | |
| 182 | |
| 183 static PluginType plugin_types[] = { | |
| 184 { "input" , "get_iplugin_info", input_plugin_init }, | |
| 185 { "output" , "get_oplugin_info", output_plugin_init }, | |
| 186 { "effect" , "get_eplugin_info", effect_plugin_init }, | |
| 187 { "general" , "get_gplugin_info", general_plugin_init }, | |
| 188 { "visualization", "get_vplugin_info", vis_plugin_init }, | |
| 189 { NULL, NULL, NULL } | |
| 190 }; | |
| 191 | |
| 192 static void | |
| 193 add_plugin(const gchar * filename) | |
| 194 { | |
| 195 PluginType *type; | |
| 196 GModule *module; | |
| 197 gpointer func; | |
| 198 | |
| 199 if (plugin_is_duplicate(filename)) | |
| 200 return; | |
| 201 | |
| 202 if (!(module = g_module_open(filename, 0))) { | |
| 12 | 203 printf("Failed to load plugin (%s): %s\n", |
| 0 | 204 filename, g_module_error()); |
| 205 return; | |
| 206 } | |
| 207 | |
| 208 for (type = plugin_types; type->name; type++) | |
| 209 { | |
| 210 if (g_module_symbol(module, type->id, &func)) { | |
| 211 Plugin *plugin = PLUGIN_GET_INFO(func); | |
| 212 | |
| 213 plugin->handle = module; | |
| 214 plugin->filename = g_strdup(filename); | |
| 215 type->init(PLUGIN_GET_INFO(func)); | |
| 216 | |
| 217 return; | |
| 218 } | |
| 219 } | |
| 220 | |
| 12 | 221 printf("Invalid plugin (%s)\n", filename); |
| 0 | 222 g_module_close(module); |
| 223 } | |
| 224 | |
| 225 static gboolean | |
| 226 scan_plugin_func(const gchar * path, const gchar * basename, gpointer data) | |
| 227 { | |
| 228 if (!str_has_suffix_nocase(basename, G_MODULE_SUFFIX)) | |
| 229 return FALSE; | |
| 230 | |
| 231 if (!g_file_test(path, G_FILE_TEST_IS_REGULAR)) | |
| 232 return FALSE; | |
| 233 | |
| 234 add_plugin(path); | |
| 235 | |
| 236 return FALSE; | |
| 237 } | |
| 238 | |
| 239 static void | |
| 240 scan_plugins(const gchar * path) | |
| 241 { | |
| 242 dir_foreach(path, scan_plugin_func, NULL, NULL); | |
| 243 } | |
| 244 | |
| 245 void | |
| 246 plugin_system_init(void) | |
| 247 { | |
| 248 gchar *dir, **disabled; | |
| 249 GList *node; | |
| 250 OutputPlugin *op; | |
| 251 InputPlugin *ip; | |
| 252 gint dirsel = 0, i = 0; | |
| 253 | |
| 254 if (!g_module_supported()) { | |
|
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
687
diff
changeset
|
255 report_error("Module loading not supported! Plugins will not be loaded.\n"); |
| 0 | 256 return; |
| 257 } | |
| 258 | |
| 259 plugin_matrix = g_hash_table_new_full(g_str_hash, g_int_equal, g_free, | |
| 260 NULL); | |
| 261 | |
| 262 #ifndef DISABLE_USER_PLUGIN_DIR | |
| 263 scan_plugins(bmp_paths[BMP_PATH_USER_PLUGIN_DIR]); | |
| 264 /* | |
| 265 * This is in a separate loop so if the user puts them in the | |
| 266 * wrong dir we'll still get them in the right order (home dir | |
| 267 * first) - Zinx | |
| 268 */ | |
| 269 while (plugin_dir_list[dirsel]) { | |
| 270 dir = g_build_filename(bmp_paths[BMP_PATH_USER_PLUGIN_DIR], | |
| 271 plugin_dir_list[dirsel++], NULL); | |
| 272 scan_plugins(dir); | |
| 273 g_free(dir); | |
| 274 } | |
| 275 dirsel = 0; | |
| 276 #endif | |
| 277 | |
| 278 while (plugin_dir_list[dirsel]) { | |
| 279 dir = g_build_filename(PLUGIN_DIR, plugin_dir_list[dirsel++], NULL); | |
| 280 scan_plugins(dir); | |
| 281 g_free(dir); | |
| 282 } | |
| 283 | |
| 284 op_data.output_list = g_list_sort(op_data.output_list, outputlist_compare_func); | |
| 285 if (!op_data.current_output_plugin | |
| 286 && g_list_length(op_data.output_list)) { | |
| 287 op_data.current_output_plugin = op_data.output_list->data; | |
| 288 } | |
| 289 | |
| 290 ip_data.input_list = g_list_sort(ip_data.input_list, inputlist_compare_func); | |
| 291 | |
| 292 ep_data.effect_list = g_list_sort(ep_data.effect_list, effectlist_compare_func); | |
| 293 ep_data.enabled_list = NULL; | |
| 294 | |
| 295 gp_data.general_list = g_list_sort(gp_data.general_list, generallist_compare_func); | |
| 296 gp_data.enabled_list = NULL; | |
| 297 | |
| 298 vp_data.vis_list = g_list_sort(vp_data.vis_list, vislist_compare_func); | |
| 299 vp_data.enabled_list = NULL; | |
| 300 | |
| 301 general_enable_from_stringified_list(cfg.enabled_gplugins); | |
| 302 vis_enable_from_stringified_list(cfg.enabled_vplugins); | |
| 303 effect_enable_from_stringified_list(cfg.enabled_eplugins); | |
| 304 | |
| 305 g_free(cfg.enabled_gplugins); | |
| 306 cfg.enabled_gplugins = NULL; | |
| 307 | |
| 308 g_free(cfg.enabled_vplugins); | |
| 309 cfg.enabled_vplugins = NULL; | |
| 310 | |
| 311 g_free(cfg.enabled_eplugins); | |
| 312 cfg.enabled_eplugins = NULL; | |
| 313 | |
| 314 for (node = op_data.output_list; node; node = g_list_next(node)) { | |
| 315 op = OUTPUT_PLUGIN(node->data); | |
| 316 /* | |
| 317 * Only test basename to avoid problems when changing | |
| 318 * prefix. We will only see one plugin with the same | |
| 319 * basename, so this is usually what the user want. | |
| 320 */ | |
| 321 if (!strcmp(g_basename(cfg.outputplugin), g_basename(op->filename))) | |
| 322 op_data.current_output_plugin = op; | |
| 323 if (op->init) | |
| 324 op->init(); | |
| 325 } | |
| 326 | |
| 327 for (node = ip_data.input_list; node; node = g_list_next(node)) { | |
| 328 ip = INPUT_PLUGIN(node->data); | |
| 329 if (ip->init) | |
| 330 ip->init(); | |
| 331 } | |
| 332 | |
| 333 if (cfg.disabled_iplugins) { | |
| 334 disabled = g_strsplit(cfg.disabled_iplugins, ":", 0); | |
| 335 while (disabled[i]) { | |
| 336 g_hash_table_replace(plugin_matrix, disabled[i], | |
| 337 GINT_TO_POINTER(FALSE)); | |
| 338 i++; | |
| 339 } | |
| 340 | |
| 341 g_free(disabled); | |
| 342 | |
| 343 g_free(cfg.disabled_iplugins); | |
| 344 cfg.disabled_iplugins = NULL; | |
| 345 } | |
| 346 } | |
| 347 | |
| 348 void | |
| 349 plugin_system_cleanup(void) | |
| 350 { | |
| 351 InputPlugin *ip; | |
| 352 OutputPlugin *op; | |
| 353 EffectPlugin *ep; | |
| 354 GeneralPlugin *gp; | |
| 355 VisPlugin *vp; | |
| 356 GList *node; | |
| 357 | |
| 358 g_message("Shutting down plugin system"); | |
| 359 | |
| 360 if (bmp_playback_get_playing()) | |
| 361 bmp_playback_stop(); | |
| 362 | |
| 363 for (node = get_input_list(); node; node = g_list_next(node)) { | |
| 364 ip = INPUT_PLUGIN(node->data); | |
| 365 if (ip && ip->cleanup) { | |
| 366 ip->cleanup(); | |
| 367 GDK_THREADS_LEAVE(); | |
| 368 while (g_main_iteration(FALSE)); | |
| 369 GDK_THREADS_ENTER(); | |
| 370 } | |
| 371 g_module_close(ip->handle); | |
| 372 } | |
| 373 | |
| 374 if (ip_data.input_list) | |
| 375 g_list_free(ip_data.input_list); | |
| 376 | |
| 377 for (node = get_output_list(); node; node = g_list_next(node)) { | |
| 378 op = OUTPUT_PLUGIN(node->data); | |
| 309 | 379 if (op && op->cleanup) { |
| 380 op->cleanup(); | |
| 381 GDK_THREADS_LEAVE(); | |
| 382 while (g_main_iteration(FALSE)); | |
| 383 GDK_THREADS_ENTER(); | |
| 384 } | |
| 0 | 385 g_module_close(op->handle); |
| 386 } | |
| 387 | |
| 388 if (op_data.output_list) | |
| 389 g_list_free(op_data.output_list); | |
| 390 | |
| 391 for (node = get_effect_list(); node; node = g_list_next(node)) { | |
| 392 ep = EFFECT_PLUGIN(node->data); | |
| 393 if (ep && ep->cleanup) { | |
| 394 ep->cleanup(); | |
| 395 GDK_THREADS_LEAVE(); | |
| 396 while (g_main_iteration(FALSE)); | |
| 397 GDK_THREADS_ENTER(); | |
| 398 } | |
| 399 g_module_close(ep->handle); | |
| 400 } | |
| 401 | |
| 402 if (ep_data.effect_list) | |
| 403 g_list_free(ep_data.effect_list); | |
| 404 | |
| 405 for (node = get_general_enabled_list(); node; node = g_list_next(node)) { | |
| 406 gp = GENERAL_PLUGIN(node->data); | |
| 407 enable_general_plugin(g_list_index(gp_data.general_list, gp), FALSE); | |
| 408 } | |
| 409 | |
| 410 if (gp_data.enabled_list) | |
| 411 g_list_free(gp_data.enabled_list); | |
| 412 | |
| 413 GDK_THREADS_LEAVE(); | |
| 414 while (g_main_iteration(FALSE)); | |
| 415 GDK_THREADS_ENTER(); | |
| 416 | |
| 417 for (node = get_general_list(); node; node = g_list_next(node)) { | |
| 418 gp = GENERAL_PLUGIN(node->data); | |
|
650
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
419 if (gp && gp->cleanup) { |
|
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
420 gp->cleanup(); |
|
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
421 GDK_THREADS_LEAVE(); |
|
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
422 while (g_main_iteration(FALSE)); |
|
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
423 GDK_THREADS_ENTER(); |
|
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
424 } |
| 0 | 425 g_module_close(gp->handle); |
| 426 } | |
| 427 | |
| 428 if (gp_data.general_list) | |
| 429 g_list_free(gp_data.general_list); | |
| 430 | |
| 431 for (node = get_vis_enabled_list(); node; node = g_list_next(node)) { | |
| 432 vp = VIS_PLUGIN(node->data); | |
| 433 enable_vis_plugin(g_list_index(vp_data.vis_list, vp), FALSE); | |
| 434 } | |
| 435 | |
| 436 if (vp_data.enabled_list) | |
| 437 g_list_free(vp_data.enabled_list); | |
| 438 | |
| 439 GDK_THREADS_LEAVE(); | |
| 440 while (g_main_iteration(FALSE)); | |
| 441 GDK_THREADS_ENTER(); | |
| 442 | |
| 443 for (node = get_vis_list(); node; node = g_list_next(node)) { | |
| 444 vp = VIS_PLUGIN(node->data); | |
|
650
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
445 if (vp && vp->cleanup) { |
|
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
446 vp->cleanup(); |
|
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
447 GDK_THREADS_LEAVE(); |
|
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
448 while (g_main_iteration(FALSE)); |
|
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
449 GDK_THREADS_ENTER(); |
|
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
450 } |
| 0 | 451 g_module_close(vp->handle); |
| 452 } | |
| 453 | |
| 454 if (vp_data.vis_list) | |
| 455 g_list_free(vp_data.vis_list); | |
| 456 } |
