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