comparison src/audacious/pluginenum.c @ 3227:2619f4c62abe trunk

added Discovery plugin type
author Cristi Magherusan <majeru@atheme-project.org>
date Fri, 03 Aug 2007 07:20:58 +0300
parents 8775dfc57ead
children 2453bf125b4f
comparison
equal deleted inserted replaced
3226:db3983f423f3 3227:2619f4c62abe
48 #include "effect.h" 48 #include "effect.h"
49 #include "general.h" 49 #include "general.h"
50 #include "input.h" 50 #include "input.h"
51 #include "output.h" 51 #include "output.h"
52 #include "visualization.h" 52 #include "visualization.h"
53 53 #include "discovery.h"
54 const gchar *plugin_dir_list[] = { 54 const gchar *plugin_dir_list[] = {
55 PLUGINSUBS, 55 PLUGINSUBS,
56 NULL 56 NULL
57 }; 57 };
58 58
59 GHashTable *plugin_matrix = NULL; 59 GHashTable *plugin_matrix = NULL;
60 GList *lowlevel_list = NULL; 60 GList *lowlevel_list = NULL;
61
62 extern GList *vfs_transports; 61 extern GList *vfs_transports;
63 62
64 static gint 63 static gint
65 inputlist_compare_func(gconstpointer a, gconstpointer b) 64 inputlist_compare_func(gconstpointer a, gconstpointer b)
66 { 65 {
109 return strcasecmp(ap->description, bp->description); 108 return strcasecmp(ap->description, bp->description);
110 else 109 else
111 return 0; 110 return 0;
112 } 111 }
113 112
113 static gint
114 discoverylist_compare_func(gconstpointer a, gconstpointer b)
115 {
116 const DiscoveryPlugin *ap = a, *bp = b;
117 if(ap->description && bp->description)
118 return strcasecmp(ap->description, bp->description);
119 else
120 return 0;
121 }
122
114 static gboolean 123 static gboolean
115 plugin_is_duplicate(const gchar * filename) 124 plugin_is_duplicate(const gchar * filename)
116 { 125 {
117 GList *l; 126 GList *l;
118 const gchar *basename = g_basename(filename); 127 const gchar *basename = g_basename(filename);
138 for (l = vp_data.vis_list; l; l = g_list_next(l)) 147 for (l = vp_data.vis_list; l; l = g_list_next(l))
139 if (!strcmp(basename, g_basename(VIS_PLUGIN(l->data)->filename))) 148 if (!strcmp(basename, g_basename(VIS_PLUGIN(l->data)->filename)))
140 return TRUE; 149 return TRUE;
141 150
142 for (l = lowlevel_list; l; l = g_list_next(l)) 151 for (l = lowlevel_list; l; l = g_list_next(l))
143 if (!strcmp(basename, g_basename(VIS_PLUGIN(l->data)->filename))) 152 if (!strcmp(basename, g_basename(LOWLEVEL_PLUGIN(l->data)->filename)))
153 return TRUE;
154
155 for (l = dp_data.discovery_list; l; l = g_list_next(l))
156 if (!strcmp(basename, g_basename(DISCOVERY_PLUGIN(l->data)->filename)))
144 return TRUE; 157 return TRUE;
145 158
146 return FALSE; 159 return FALSE;
147 } 160 }
148 161
198 VisPlugin *p = VIS_PLUGIN(plugin); 211 VisPlugin *p = VIS_PLUGIN(plugin);
199 p->disable_plugin = vis_disable_plugin; 212 p->disable_plugin = vis_disable_plugin;
200 vp_data.vis_list = g_list_append(vp_data.vis_list, p); 213 vp_data.vis_list = g_list_append(vp_data.vis_list, p);
201 } 214 }
202 215
216 static void
217 discovery_plugin_init(Plugin * plugin)
218 {
219 DiscoveryPlugin *p = DISCOVERY_PLUGIN(plugin);
220 dp_data.discovery_list = g_list_append(dp_data.discovery_list, p);
221 }
222
203 /*******************************************************************/ 223 /*******************************************************************/
204 224
205 static void 225 static void
206 plugin2_dispose(GModule *module, const gchar *str, ...) 226 plugin2_dispose(GModule *module, const gchar *str, ...)
207 { 227 {
222 InputPlugin **ip_iter; 242 InputPlugin **ip_iter;
223 OutputPlugin **op_iter; 243 OutputPlugin **op_iter;
224 EffectPlugin **ep_iter; 244 EffectPlugin **ep_iter;
225 GeneralPlugin **gp_iter; 245 GeneralPlugin **gp_iter;
226 VisPlugin **vp_iter; 246 VisPlugin **vp_iter;
247 DiscoveryPlugin **dp_iter;
248
227 249
228 if (header->magic != PLUGIN_MAGIC) 250 if (header->magic != PLUGIN_MAGIC)
229 return plugin2_dispose(module, "plugin <%s> discarded, invalid module magic", filename); 251 return plugin2_dispose(module, "plugin <%s> discarded, invalid module magic", filename);
230 252
231 #if 0 253 #if 0
288 PLUGIN(*vp_iter)->filename = g_strdup(filename); 310 PLUGIN(*vp_iter)->filename = g_strdup(filename);
289 g_print("plugin2 '%s' provides VisPlugin <%p>\n", filename, *vp_iter); 311 g_print("plugin2 '%s' provides VisPlugin <%p>\n", filename, *vp_iter);
290 vis_plugin_init(PLUGIN(*vp_iter)); 312 vis_plugin_init(PLUGIN(*vp_iter));
291 } 313 }
292 } 314 }
315
316 if (header->dp_list)
317 {
318 for (dp_iter = header->dp_list; *dp_iter != NULL; dp_iter++)
319 {
320 PLUGIN(*dp_iter)->filename = g_strdup(filename);
321 g_print("plugin2 '%s' provides DiscoveryPlugin <%p>\n", filename, *dp_iter);
322 discovery_plugin_init(PLUGIN(*dp_iter));
323 }
324 }
325
293 } 326 }
294 327
295 void 328 void
296 plugin2_unload(PluginHeader *header) 329 plugin2_unload(PluginHeader *header)
297 { 330 {
372 gchar *dir, **disabled; 405 gchar *dir, **disabled;
373 GList *node; 406 GList *node;
374 OutputPlugin *op; 407 OutputPlugin *op;
375 InputPlugin *ip; 408 InputPlugin *ip;
376 LowlevelPlugin *lp; 409 LowlevelPlugin *lp;
410 DiscoveryPlugin *dp;
377 gint dirsel = 0, i = 0; 411 gint dirsel = 0, i = 0;
378 412
379 if (!g_module_supported()) { 413 if (!g_module_supported()) {
380 report_error("Module loading not supported! Plugins will not be loaded.\n"); 414 report_error("Module loading not supported! Plugins will not be loaded.\n");
381 return; 415 return;
385 NULL); 419 NULL);
386 420
387 #ifndef DISABLE_USER_PLUGIN_DIR 421 #ifndef DISABLE_USER_PLUGIN_DIR
388 scan_plugins(bmp_paths[BMP_PATH_USER_PLUGIN_DIR]); 422 scan_plugins(bmp_paths[BMP_PATH_USER_PLUGIN_DIR]);
389 /* 423 /*
390 * This is in a separate loop so if the user puts them in the 424 * This is in a separate lo
425 * DiscoveryPlugin *dpop so if the user puts them in the
391 * wrong dir we'll still get them in the right order (home dir 426 * wrong dir we'll still get them in the right order (home dir
392 * first) - Zinx 427 * first) - Zinx
393 */ 428 */
394 while (plugin_dir_list[dirsel]) { 429 while (plugin_dir_list[dirsel]) {
395 dir = g_build_filename(bmp_paths[BMP_PATH_USER_PLUGIN_DIR], 430 dir = g_build_filename(bmp_paths[BMP_PATH_USER_PLUGIN_DIR],
421 gp_data.enabled_list = NULL; 456 gp_data.enabled_list = NULL;
422 457
423 vp_data.vis_list = g_list_sort(vp_data.vis_list, vislist_compare_func); 458 vp_data.vis_list = g_list_sort(vp_data.vis_list, vislist_compare_func);
424 vp_data.enabled_list = NULL; 459 vp_data.enabled_list = NULL;
425 460
461 dp_data.discovery_list = g_list_sort(dp_data.discovery_list, discoverylist_compare_func);
462 dp_data.enabled_list = NULL;
463
464
426 general_enable_from_stringified_list(cfg.enabled_gplugins); 465 general_enable_from_stringified_list(cfg.enabled_gplugins);
427 vis_enable_from_stringified_list(cfg.enabled_vplugins); 466 vis_enable_from_stringified_list(cfg.enabled_vplugins);
428 effect_enable_from_stringified_list(cfg.enabled_eplugins); 467 effect_enable_from_stringified_list(cfg.enabled_eplugins);
468 discovery_enable_from_stringified_list(cfg.enabled_dplugins);
429 469
430 g_free(cfg.enabled_gplugins); 470 g_free(cfg.enabled_gplugins);
431 cfg.enabled_gplugins = NULL; 471 cfg.enabled_gplugins = NULL;
432 472
433 g_free(cfg.enabled_vplugins); 473 g_free(cfg.enabled_vplugins);
434 cfg.enabled_vplugins = NULL; 474 cfg.enabled_vplugins = NULL;
435 475
436 g_free(cfg.enabled_eplugins); 476 g_free(cfg.enabled_eplugins);
437 cfg.enabled_eplugins = NULL; 477 cfg.enabled_eplugins = NULL;
478
479 g_free(cfg.enabled_dplugins);
480 cfg.enabled_dplugins = NULL;
481
438 482
439 for (node = op_data.output_list; node; node = g_list_next(node)) { 483 for (node = op_data.output_list; node; node = g_list_next(node)) {
440 op = OUTPUT_PLUGIN(node->data); 484 op = OUTPUT_PLUGIN(node->data);
441 /* 485 /*
442 * Only test basename to avoid problems when changing 486 * Only test basename to avoid problems when changing
453 ip = INPUT_PLUGIN(node->data); 497 ip = INPUT_PLUGIN(node->data);
454 if (ip->init) 498 if (ip->init)
455 ip->init(); 499 ip->init();
456 } 500 }
457 501
502 for (node = dp_data.discovery_list; node; node = g_list_next(node)) {
503 dp = DISCOVERY_PLUGIN(node->data);
504 if (dp->init)
505 dp->init();
506 }
507
508
458 for (node = lowlevel_list; node; node = g_list_next(node)) { 509 for (node = lowlevel_list; node; node = g_list_next(node)) {
459 lp = LOWLEVEL_PLUGIN(node->data); 510 lp = LOWLEVEL_PLUGIN(node->data);
460 if (lp->init) 511 if (lp->init)
461 lp->init(); 512 lp->init();
462 } 513 }
483 OutputPlugin *op; 534 OutputPlugin *op;
484 EffectPlugin *ep; 535 EffectPlugin *ep;
485 GeneralPlugin *gp; 536 GeneralPlugin *gp;
486 VisPlugin *vp; 537 VisPlugin *vp;
487 LowlevelPlugin *lp; 538 LowlevelPlugin *lp;
539 DiscoveryPlugin *dp;
488 GList *node; 540 GList *node;
489 541
490 g_message("Shutting down plugin system"); 542 g_message("Shutting down plugin system");
491 543
492 if (playback_get_playing()) { 544 if (playback_get_playing()) {
591 { 643 {
592 g_list_free(vp_data.vis_list); 644 g_list_free(vp_data.vis_list);
593 vp_data.vis_list = NULL; 645 vp_data.vis_list = NULL;
594 } 646 }
595 647
648
649 for (node = get_discovery_list(); node; node = g_list_next(node)) {
650 dp = DISCOVERY_PLUGIN(node->data);
651 if (dp && dp->cleanup) {
652 dp->cleanup();
653 GDK_THREADS_LEAVE();
654 while (g_main_context_iteration(NULL, FALSE));
655 GDK_THREADS_ENTER();
656 }
657
658 if (dp->handle)
659 g_module_close(dp->handle);
660 }
661
662 if (dp_data.discovery_list != NULL)
663 {
664 g_list_free(dp_data.discovery_list);
665 dp_data.discovery_list = NULL;
666 }
667
668
669
596 for (node = lowlevel_list; node; node = g_list_next(node)) { 670 for (node = lowlevel_list; node; node = g_list_next(node)) {
597 lp = LOWLEVEL_PLUGIN(node->data); 671 lp = LOWLEVEL_PLUGIN(node->data);
598 if (lp && lp->cleanup) { 672 if (lp && lp->cleanup) {
599 lp->cleanup(); 673 lp->cleanup();
600 GDK_THREADS_LEAVE(); 674 GDK_THREADS_LEAVE();