Mercurial > audlegacy
comparison src/audacious/pluginenum.c @ 2797:f0c1c8b22c88 trunk
[svn] - first attempt at an plugin API2 loader. this is entirely implemented inside the plugin2 namespace, so please respect that if you go editing this ;p
| author | nenolod |
|---|---|
| date | Thu, 24 May 2007 03:27:54 -0700 |
| parents | fa6c339cce38 |
| children | 7144a4e5e978 |
comparison
equal
deleted
inserted
replaced
| 2796:e9af66a1be74 | 2797:f0c1c8b22c88 |
|---|---|
| 188 { | 188 { |
| 189 LowlevelPlugin *p = LOWLEVEL_PLUGIN(plugin); | 189 LowlevelPlugin *p = LOWLEVEL_PLUGIN(plugin); |
| 190 lowlevel_list = g_list_append(lowlevel_list, p); | 190 lowlevel_list = g_list_append(lowlevel_list, p); |
| 191 } | 191 } |
| 192 | 192 |
| 193 /*******************************************************************/ | |
| 194 | |
| 195 static void | |
| 196 plugin2_dispose(GModule *module, const gchar *str, ...) | |
| 197 { | |
| 198 gchar buf[4096]; | |
| 199 va_list va; | |
| 200 | |
| 201 va_start(va, str); | |
| 202 vsnprintf(buf, 4096, str, va); | |
| 203 va_end(va); | |
| 204 | |
| 205 g_print("*** %s\n", buf); | |
| 206 g_module_close(module); | |
| 207 } | |
| 208 | |
| 209 void | |
| 210 plugin2_process(PluginHeader *header, GModule *module, const gchar *filename) | |
| 211 { | |
| 212 InputPlugin **ip_iter; | |
| 213 OutputPlugin **op_iter; | |
| 214 EffectPlugin **ep_iter; | |
| 215 GeneralPlugin **gp_iter; | |
| 216 VisPlugin **vp_iter; | |
| 217 | |
| 218 if (header->magic != PLUGIN_MAGIC) | |
| 219 return plugin2_dispose(module, "plugin <%s> discarded, invalid module magic", filename); | |
| 220 | |
| 221 if (header->api_version != __AUDACIOUS_PLUGIN_API__) | |
| 222 return plugin2_dispose(module, "plugin <%s> discarded, wanting API version %d, we implement API version %d", | |
| 223 filename, header->api_version, __AUDACIOUS_PLUGIN_API__); | |
| 224 | |
| 225 if (header->init) | |
| 226 header->init(); | |
| 227 | |
| 228 header->priv_assoc = g_new0(Plugin, 1); | |
| 229 header->priv_assoc->handle = module; | |
| 230 header->priv_assoc->filename = g_strdup(filename); | |
| 231 | |
| 232 for (ip_iter = header->ip_list; *ip_iter != NULL; ip_iter++) | |
| 233 { | |
| 234 g_print("plugin2 '%s' provides InputPlugin <%p>", filename, *ip_iter); | |
| 235 input_plugin_init(PLUGIN(*ip_iter)); | |
| 236 } | |
| 237 | |
| 238 for (op_iter = header->op_list; *op_iter != NULL; op_iter++) | |
| 239 { | |
| 240 g_print("plugin2 '%s' provides OutputPlugin <%p>", filename, *op_iter); | |
| 241 output_plugin_init(PLUGIN(*op_iter)); | |
| 242 } | |
| 243 | |
| 244 for (ep_iter = header->ep_list; *ep_iter != NULL; ep_iter++) | |
| 245 { | |
| 246 g_print("plugin2 '%s' provides EffectPlugin <%p>", filename, *ep_iter); | |
| 247 effect_plugin_init(PLUGIN(*ep_iter)); | |
| 248 } | |
| 249 | |
| 250 for (gp_iter = header->gp_list; *gp_iter != NULL; gp_iter++) | |
| 251 { | |
| 252 g_print("plugin2 '%s' provides GeneralPlugin <%p>", filename, *gp_iter); | |
| 253 general_plugin_init(PLUGIN(*gp_iter)); | |
| 254 } | |
| 255 | |
| 256 for (vp_iter = header->vp_list; *vp_iter != NULL; vp_iter++) | |
| 257 { | |
| 258 g_print("plugin2 '%s' provides VisPlugin <%p>", filename, *vp_iter); | |
| 259 vis_plugin_init(PLUGIN(*vp_iter)); | |
| 260 } | |
| 261 } | |
| 262 | |
| 263 void | |
| 264 plugin2_unload(PluginHeader *header) | |
| 265 { | |
| 266 GModule *module; | |
| 267 | |
| 268 g_return_if_fail(header->priv_assoc != NULL); | |
| 269 | |
| 270 module = header->priv_assoc->handle; | |
| 271 | |
| 272 g_free(header->priv_assoc->filename); | |
| 273 g_free(header->priv_assoc); | |
| 274 | |
| 275 if (header->fini) | |
| 276 header->fini(); | |
| 277 | |
| 278 g_module_close(module); | |
| 279 } | |
| 280 | |
| 281 /******************************************************************/ | |
| 282 | |
| 193 /* FIXME: Placed here (hopefully) temporarily - descender */ | 283 /* FIXME: Placed here (hopefully) temporarily - descender */ |
| 194 | 284 |
| 195 typedef struct { | 285 typedef struct { |
| 196 const gchar *name; | 286 const gchar *name; |
| 197 const gchar *id; | 287 const gchar *id; |
| 224 printf("Failed to load plugin (%s): %s\n", | 314 printf("Failed to load plugin (%s): %s\n", |
| 225 filename, g_module_error()); | 315 filename, g_module_error()); |
| 226 return; | 316 return; |
| 227 } | 317 } |
| 228 | 318 |
| 319 /* v2 plugin loading */ | |
| 320 if (g_module_symbol(module, "get_plugin_info", &func)) | |
| 321 { | |
| 322 PluginHeader *(*header_func_p)() = func; | |
| 323 PluginHeader *header; | |
| 324 | |
| 325 /* this should never happen. */ | |
| 326 g_return_if_fail((header = header_func_p()) != NULL); | |
| 327 | |
| 328 plugin2_process(header, module, filename); | |
| 329 return; | |
| 330 } | |
| 331 | |
| 332 /* v1 plugin loading */ | |
| 229 for (type = plugin_types; type->name; type++) | 333 for (type = plugin_types; type->name; type++) |
| 230 { | 334 { |
| 231 if (g_module_symbol(module, type->id, &func)) { | 335 if (g_module_symbol(module, type->id, &func)) { |
| 232 Plugin *plugin = PLUGIN_GET_INFO(func); | 336 Plugin *plugin = PLUGIN_GET_INFO(func); |
| 233 | 337 |
| 401 ip->cleanup(); | 505 ip->cleanup(); |
| 402 GDK_THREADS_LEAVE(); | 506 GDK_THREADS_LEAVE(); |
| 403 while (g_main_context_iteration(NULL, FALSE)); | 507 while (g_main_context_iteration(NULL, FALSE)); |
| 404 GDK_THREADS_ENTER(); | 508 GDK_THREADS_ENTER(); |
| 405 } | 509 } |
| 406 g_module_close(ip->handle); | 510 |
| 511 if (ip->handle) | |
| 512 g_module_close(ip->handle); | |
| 407 } | 513 } |
| 408 | 514 |
| 409 if (ip_data.input_list != NULL) | 515 if (ip_data.input_list != NULL) |
| 410 { | 516 { |
| 411 g_list_free(ip_data.input_list); | 517 g_list_free(ip_data.input_list); |
| 418 op->cleanup(); | 524 op->cleanup(); |
| 419 GDK_THREADS_LEAVE(); | 525 GDK_THREADS_LEAVE(); |
| 420 while (g_main_context_iteration(NULL, FALSE)); | 526 while (g_main_context_iteration(NULL, FALSE)); |
| 421 GDK_THREADS_ENTER(); | 527 GDK_THREADS_ENTER(); |
| 422 } | 528 } |
| 423 g_module_close(op->handle); | 529 |
| 530 if (op->handle) | |
| 531 g_module_close(op->handle); | |
| 424 } | 532 } |
| 425 | 533 |
| 426 if (op_data.output_list != NULL) | 534 if (op_data.output_list != NULL) |
| 427 { | 535 { |
| 428 g_list_free(op_data.output_list); | 536 g_list_free(op_data.output_list); |
| 435 ep->cleanup(); | 543 ep->cleanup(); |
| 436 GDK_THREADS_LEAVE(); | 544 GDK_THREADS_LEAVE(); |
| 437 while (g_main_context_iteration(NULL, FALSE)); | 545 while (g_main_context_iteration(NULL, FALSE)); |
| 438 GDK_THREADS_ENTER(); | 546 GDK_THREADS_ENTER(); |
| 439 } | 547 } |
| 440 g_module_close(ep->handle); | 548 |
| 549 if (ep->handle) | |
| 550 g_module_close(ep->handle); | |
| 441 } | 551 } |
| 442 | 552 |
| 443 if (ep_data.effect_list != NULL) | 553 if (ep_data.effect_list != NULL) |
| 444 { | 554 { |
| 445 g_list_free(ep_data.effect_list); | 555 g_list_free(ep_data.effect_list); |
| 452 gp->cleanup(); | 562 gp->cleanup(); |
| 453 GDK_THREADS_LEAVE(); | 563 GDK_THREADS_LEAVE(); |
| 454 while (g_main_context_iteration(NULL, FALSE)); | 564 while (g_main_context_iteration(NULL, FALSE)); |
| 455 GDK_THREADS_ENTER(); | 565 GDK_THREADS_ENTER(); |
| 456 } | 566 } |
| 457 g_module_close(gp->handle); | 567 |
| 568 if (gp->handle) | |
| 569 g_module_close(gp->handle); | |
| 458 } | 570 } |
| 459 | 571 |
| 460 if (gp_data.general_list != NULL) | 572 if (gp_data.general_list != NULL) |
| 461 { | 573 { |
| 462 g_list_free(gp_data.general_list); | 574 g_list_free(gp_data.general_list); |
| 469 vp->cleanup(); | 581 vp->cleanup(); |
| 470 GDK_THREADS_LEAVE(); | 582 GDK_THREADS_LEAVE(); |
| 471 while (g_main_context_iteration(NULL, FALSE)); | 583 while (g_main_context_iteration(NULL, FALSE)); |
| 472 GDK_THREADS_ENTER(); | 584 GDK_THREADS_ENTER(); |
| 473 } | 585 } |
| 474 g_module_close(vp->handle); | 586 |
| 587 if (vp->handle) | |
| 588 g_module_close(vp->handle); | |
| 475 } | 589 } |
| 476 | 590 |
| 477 if (vp_data.vis_list != NULL) | 591 if (vp_data.vis_list != NULL) |
| 478 { | 592 { |
| 479 g_list_free(vp_data.vis_list); | 593 g_list_free(vp_data.vis_list); |
| 486 lp->cleanup(); | 600 lp->cleanup(); |
| 487 GDK_THREADS_LEAVE(); | 601 GDK_THREADS_LEAVE(); |
| 488 while (g_main_context_iteration(NULL, FALSE)); | 602 while (g_main_context_iteration(NULL, FALSE)); |
| 489 GDK_THREADS_ENTER(); | 603 GDK_THREADS_ENTER(); |
| 490 } | 604 } |
| 491 g_module_close(lp->handle); | 605 |
| 606 if (lp->handle) | |
| 607 g_module_close(lp->handle); | |
| 492 } | 608 } |
| 493 | 609 |
| 494 if (lowlevel_list != NULL) | 610 if (lowlevel_list != NULL) |
| 495 { | 611 { |
| 496 g_list_free(lowlevel_list); | 612 g_list_free(lowlevel_list); |
