From aae3c8ed81567cbd82baae88e02f14cbdd4610b1 Mon Sep 17 00:00:00 2001 From: Christian Thaeter Date: Thu, 6 Nov 2008 05:23:47 +0100 Subject: [PATCH] LUMIERA_PLUGIN is dead, long life LUMIERA_PLUGIN removes the difference in compiled in and plugin interfaces. * All interfaces are now defined with LUMIERA_EXPORT(...) * The definition of LUMIERA_PLUGIN at compile time takes action to compile as plugin which gets automatically managed. * compiled in (core) interfaces need still be registered, this is simplified with the LUMIERA_INTERFACE_REGISTEREXPORTED and LUMIERA_INTERFACE_UNREGISTEREXPORTED macros which become no-ops for plugins. --- src/backend/interface.h | 64 +++++++++++++++++------------ tests/Makefile.am | 2 +- tests/backend/example_plugin.c | 45 ++++++++++----------- tests/backend/test-interfaces.c | 72 ++++++++++++++++----------------- 4 files changed, 96 insertions(+), 87 deletions(-) diff --git a/src/backend/interface.h b/src/backend/interface.h index c84238d1c..e962a2d10 100644 --- a/src/backend/interface.h +++ b/src/backend/interface.h @@ -268,16 +268,16 @@ LUMIERA_INTERFACE_INSTANCE (iname, version, /** * Generate interface container suitable for enumerating interfaces. * This takes a list of interface definitions, instantiates them and places pointers to them - * into a zero terminated array which address is returned by the a created function. - * For interfaces generated by he core, the user is responsible to register these at the - * plugindb dynamically - * @param queryfunc name of the function to be created. - * @param ... list of LUMIERA_INTERFACE_DEFINE() for all interfaces this plugin provides. + * into a zero terminated array which address is returned by a static function named 'lumiera_plugin_interfaces'. + * For interfaces generated by he core, the user is responsible to register these dynamically. + * When LUMIERA_PLUGIN is defined, things change and an additional 'lumieraorg__plugin' interface is generated. + * The plugin loader then uses this to register the provided interfaces automatically. + * @param ... list of LUMIERA_INTERFACE_DEFINE()/LUMIERA_INTERFACE_INLINE() for all interfaces this plugin provides. */ -#define LUMIERA_EXPORT(queryfunc, ...) \ +#define LUMIERA_EXPORT(...) \ PPMPL_FOREACH_L1(_P1_, __VA_ARGS__) \ static LumieraInterface* \ -queryfunc (void) \ +lumiera_plugin_interfaces (void) \ { \ static LumieraInterface interfaces[] = \ { \ @@ -285,30 +285,42 @@ queryfunc (void) \ NULL \ }; \ return interfaces; \ -} +} \ +LUMIERA_PLUGININTERFACE /** - * Generate interface container suitable for a lumiera plugin. - * This takes a list of interface definitions and places pointers to them into a zero terminated array. Further - * it instances a local 'plugin interface' which will be picked up by the plugin loader to query the array of - * provided interfaces. - * @param descriptor pointer to an interface instance which provides a description of this plugin, might be NULL - * @param acquire a function which is called whenever the plugin interface is opened for using, might be NULL - * @param release a function which is called whenever this plugin interface is closed after use, might be NULL - * @param luid unique identifier for the this plugin interfaces query, use the magic word LUIDGEN here and run the - * lumiera uuid generator tool (to be written) over the source file to generate luid's automatically - * @param ... list of LUMIERA_INTERFACE_DEFINE() for all interfaces this plugin provides. + * Create a plugin interface when being copiled as plugin */ -#define LUMIERA_PLUGIN(acquire, release, luid, ...) \ -LUMIERA_EXPORT(plugin_interfaces, __VA_ARGS__) \ -LUMIERA_INTERFACE_INSTANCE (lumieraorg__plugin, 0, \ - lumieraorg_plugin, \ - NULL, \ - acquire, \ - release, \ - LUMIERA_INTERFACE_MAP (plugin_interfaces, luid, plugin_interfaces) \ +#ifdef LUMIERA_PLUGIN +#define LUMIERA_PLUGININTERFACE \ +LUMIERA_INTERFACE_INSTANCE (lumieraorg__plugin, 0, \ + lumieraorg_plugin, \ + NULL, \ + NULL, \ + NULL, \ + LUMIERA_INTERFACE_MAP (plugin_interfaces, \ + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", \ + lumiera_plugin_interfaces) \ ); +#define LUMIERA_INTERFACE_REGISTEREXPORTED +#define LUMIERA_INTERFACE_UNREGISTEREXPORTED +#else +#define LUMIERA_PLUGININTERFACE +/** + * Register all exported interfaces when not a plugin + * This is a no-op when LUMIERA_PLUGIN is defined, since plugins are automatically registered + */ +#define LUMIERA_INTERFACE_REGISTEREXPORTED \ + lumiera_interfaceregistry_bulkregister_interfaces (lumiera_plugin_interfaces(), NULL) +/** + * Unregister all exported interfaces when not a plugin + * This is a no-op when LUMIERA_PLUGIN is defined, since plugins are automatically registered + */ +#define LUMIERA_INTERFACE_UNREGISTEREXPORTED \ + lumiera_interfaceregistry_bulkremove_interfaces (lumiera_plugin_interfaces()) +#endif + /** * create a handle for a interface (WIP) diff --git a/tests/Makefile.am b/tests/Makefile.am index 12be3704d..ce422a4e8 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -65,7 +65,7 @@ test_config_LDADD = liblumibackend.a liblumiera.a $(NOBUGMT_LUMIERA_LIBS) check_LTLIBRARIES += examplepluginc.la examplepluginc_la_SOURCES = $(tests_srcdir)/backend/example_plugin.c -examplepluginc_la_CPPFLAGS = $(AM_CPPFLAGS) -std=gnu99 -Wall -Werror -I$(top_srcdir)/src/ +examplepluginc_la_CPPFLAGS = $(AM_CPPFLAGS) -std=gnu99 -Wall -Werror -DLUMIERA_PLUGIN -I$(top_srcdir)/src/ examplepluginc_la_LDFLAGS = -module -avoid-version -no-undefined -rpath /dev/null check_PROGRAMS += test-interfaces diff --git a/tests/backend/example_plugin.c b/tests/backend/example_plugin.c index 346585190..66a93c838 100644 --- a/tests/backend/example_plugin.c +++ b/tests/backend/example_plugin.c @@ -103,26 +103,25 @@ LUMIERA_INTERFACE_INSTANCE (lumieraorg_interfacedescriptor, 0, ); -LUMIERA_PLUGIN (NULL, NULL, - "\046\150\040\062\077\110\134\143\236\244\346\365\072\377\371\263", - LUMIERA_INTERFACE_DEFINE (lumieraorg_testhello, 0, - lumieraorg_hello_german, - LUMIERA_INTERFACE_REF (lumieraorg_interfacedescriptor, 0, lumieraorg_exampleplugin_descriptor), - NULL, - NULL, - LUMIERA_INTERFACE_MAP (hello, "\167\012\306\023\031\151\006\362\026\003\125\017\170\022\100\333", - hallo), - LUMIERA_INTERFACE_MAP (goodbye, "\324\267\214\166\340\213\155\053\157\125\064\264\167\235\020\223", - tschuess) - ), - LUMIERA_INTERFACE_DEFINE (lumieraorg_testhello, 0, - lumieraorg_hello_english, - LUMIERA_INTERFACE_REF (lumieraorg_interfacedescriptor, 0, lumieraorg_exampleplugin_descriptor), - NULL, - NULL, - LUMIERA_INTERFACE_MAP (hello, "\326\247\370\247\032\103\223\357\262\007\356\042\051\330\073\116", - hello), - LUMIERA_INTERFACE_MAP (goodbye, "\365\141\371\047\101\230\050\106\071\231\022\235\325\112\354\241", - bye) - ) - ) +LUMIERA_EXPORT( + LUMIERA_INTERFACE_DEFINE (lumieraorg_testhello, 0, + lumieraorg_hello_german, + LUMIERA_INTERFACE_REF (lumieraorg_interfacedescriptor, 0, lumieraorg_exampleplugin_descriptor), + NULL, + NULL, + LUMIERA_INTERFACE_MAP (hello, "\167\012\306\023\031\151\006\362\026\003\125\017\170\022\100\333", + hallo), + LUMIERA_INTERFACE_MAP (goodbye, "\324\267\214\166\340\213\155\053\157\125\064\264\167\235\020\223", + tschuess) + ), + LUMIERA_INTERFACE_DEFINE (lumieraorg_testhello, 0, + lumieraorg_hello_english, + LUMIERA_INTERFACE_REF (lumieraorg_interfacedescriptor, 0, lumieraorg_exampleplugin_descriptor), + NULL, + NULL, + LUMIERA_INTERFACE_MAP (hello, "\326\247\370\247\032\103\223\357\262\007\356\042\051\330\073\116", + hello), + LUMIERA_INTERFACE_MAP (goodbye, "\365\141\371\047\101\230\050\106\071\231\022\235\325\112\354\241", + bye) + ) + ) diff --git a/tests/backend/test-interfaces.c b/tests/backend/test-interfaces.c index f4355cc3b..a087da735 100644 --- a/tests/backend/test-interfaces.c +++ b/tests/backend/test-interfaces.c @@ -146,28 +146,6 @@ LUMIERA_INTERFACE_INSTANCE (lumieraorg_interfacedescriptor, 0, -LUMIERA_EXPORT (interfaces_defined_here, - LUMIERA_INTERFACE_DEFINE (lumieraorg_testexample_one, 0, - lumieraorg_first_test, - LUMIERA_INTERFACE_REF(lumieraorg_interfacedescriptor, 0, lumieraorg_tests_descriptor), - testacquire, - testrelease, - LUMIERA_INTERFACE_MAP (foo1, "\214\310\136\372\003\344\163\377\075\100\070\200\375\221\227\324", - testfunc), - LUMIERA_INTERFACE_MAP (bar1, "\262\253\067\211\157\052\212\140\114\334\231\250\340\075\214\030", - testfunc) - ), - LUMIERA_INTERFACE_DEFINE (lumieraorg_testexample_two, 0, - lumieraorg_second_test, - LUMIERA_INTERFACE_REF(lumieraorg_interfacedescriptor, 0, lumieraorg_tests_descriptor), - testacquire, - testrelease, - LUMIERA_INTERFACE_MAP (foo2, "\110\152\002\271\363\052\324\272\373\045\132\270\277\000\271\217", - testfunc), - LUMIERA_INTERFACE_MAP (bar2, "\376\042\027\336\355\113\132\233\350\312\170\077\377\370\356\167", - testfunc) - ) - ); /* @@ -267,7 +245,27 @@ testrelease_four (LumieraInterface self) } -LUMIERA_EXPORT (dependencytests, +LUMIERA_EXPORT ( + LUMIERA_INTERFACE_DEFINE (lumieraorg_testexample_one, 0, + lumieraorg_first_test, + LUMIERA_INTERFACE_REF(lumieraorg_interfacedescriptor, 0, lumieraorg_tests_descriptor), + testacquire, + testrelease, + LUMIERA_INTERFACE_MAP (foo1, "\214\310\136\372\003\344\163\377\075\100\070\200\375\221\227\324", + testfunc), + LUMIERA_INTERFACE_MAP (bar1, "\262\253\067\211\157\052\212\140\114\334\231\250\340\075\214\030", + testfunc) + ), + LUMIERA_INTERFACE_DEFINE (lumieraorg_testexample_two, 0, + lumieraorg_second_test, + LUMIERA_INTERFACE_REF(lumieraorg_interfacedescriptor, 0, lumieraorg_tests_descriptor), + testacquire, + testrelease, + LUMIERA_INTERFACE_MAP (foo2, "\110\152\002\271\363\052\324\272\373\045\132\270\277\000\271\217", + testfunc), + LUMIERA_INTERFACE_MAP (bar2, "\376\042\027\336\355\113\132\233\350\312\170\077\377\370\356\167", + testfunc) + ), LUMIERA_INTERFACE_DEFINE (lumieraorg_testexample_void, 0, lumieraorg_dependencytest_one, LUMIERA_INTERFACE_REF(lumieraorg_interfacedescriptor, 0, lumieraorg_tests_descriptor), @@ -301,7 +299,7 @@ TEST ("basic") { lumiera_interfaceregistry_init (); - lumiera_interfaceregistry_bulkregister_interfaces (interfaces_defined_here(), NULL); + lumiera_interfaceregistry_bulkregister_interfaces (lumiera_plugin_interfaces(), NULL); /* some ugly lowlevel handling tests */ @@ -317,14 +315,14 @@ TEST ("basic") handle2->foo2 ("this is foo2"); - lumiera_interfaceregistry_bulkremove_interfaces (interfaces_defined_here()); + LUMIERA_INTERFACE_UNREGISTEREXPORTED; lumiera_interfaceregistry_destroy (); } TEST ("open_close") { lumiera_interfaceregistry_init (); - lumiera_interfaceregistry_bulkregister_interfaces (interfaces_defined_here(), NULL); + lumiera_interfaceregistry_bulkregister_interfaces (lumiera_plugin_interfaces(), NULL); LUMIERA_INTERFACE_HANDLE(lumieraorg_testexample_one, 0) handle = LUMIERA_INTERFACE_OPEN (lumieraorg_testexample_one, 0, 0, lumieraorg_first_test); @@ -334,14 +332,14 @@ TEST ("open_close") lumiera_interface_close ((LumieraInterface)handle); - lumiera_interfaceregistry_bulkremove_interfaces (interfaces_defined_here()); + LUMIERA_INTERFACE_UNREGISTEREXPORTED; lumiera_interfaceregistry_destroy (); } TEST ("dependencies_one") { lumiera_interfaceregistry_init (); - lumiera_interfaceregistry_bulkregister_interfaces (dependencytests(), NULL); + LUMIERA_INTERFACE_REGISTEREXPORTED; LUMIERA_INTERFACE_HANDLE(lumieraorg_testexample_void, 0) handle = LUMIERA_INTERFACE_OPEN (lumieraorg_testexample_void, 0, 0, lumieraorg_dependencytest_one); @@ -351,7 +349,7 @@ TEST ("dependencies_one") lumiera_interface_close ((LumieraInterface)handle); - lumiera_interfaceregistry_bulkremove_interfaces (dependencytests()); + LUMIERA_INTERFACE_UNREGISTEREXPORTED; lumiera_interfaceregistry_destroy (); } @@ -359,7 +357,7 @@ TEST ("dependencies_one") TEST ("dependencies_two") { lumiera_interfaceregistry_init (); - lumiera_interfaceregistry_bulkregister_interfaces (dependencytests(), NULL); + LUMIERA_INTERFACE_REGISTEREXPORTED; LUMIERA_INTERFACE_HANDLE(lumieraorg_testexample_void, 0) handle = LUMIERA_INTERFACE_OPEN (lumieraorg_testexample_void, 0, 0, lumieraorg_dependencytest_two); @@ -369,14 +367,14 @@ TEST ("dependencies_two") lumiera_interface_close ((LumieraInterface)handle); - lumiera_interfaceregistry_bulkremove_interfaces (dependencytests()); + LUMIERA_INTERFACE_UNREGISTEREXPORTED; lumiera_interfaceregistry_destroy (); } TEST ("dependencies_three") { lumiera_interfaceregistry_init (); - lumiera_interfaceregistry_bulkregister_interfaces (dependencytests(), NULL); + LUMIERA_INTERFACE_REGISTEREXPORTED; LUMIERA_INTERFACE_HANDLE(lumieraorg_testexample_void, 0) handle = LUMIERA_INTERFACE_OPEN (lumieraorg_testexample_void, 0, 0, lumieraorg_dependencytest_three); @@ -386,7 +384,7 @@ TEST ("dependencies_three") lumiera_interface_close ((LumieraInterface)handle); - lumiera_interfaceregistry_bulkremove_interfaces (dependencytests()); + LUMIERA_INTERFACE_UNREGISTEREXPORTED; lumiera_interfaceregistry_destroy (); } @@ -394,7 +392,7 @@ TEST ("dependencies_three") TEST ("dependencies_four") { lumiera_interfaceregistry_init (); - lumiera_interfaceregistry_bulkregister_interfaces (dependencytests(), NULL); + LUMIERA_INTERFACE_REGISTEREXPORTED; LUMIERA_INTERFACE_HANDLE(lumieraorg_testexample_void, 0) handle = LUMIERA_INTERFACE_OPEN (lumieraorg_testexample_void, 0, 0, lumieraorg_dependencytest_four); @@ -404,7 +402,7 @@ TEST ("dependencies_four") lumiera_interface_close ((LumieraInterface)handle); - lumiera_interfaceregistry_bulkremove_interfaces (dependencytests()); + LUMIERA_INTERFACE_UNREGISTEREXPORTED; lumiera_interfaceregistry_destroy (); } @@ -413,7 +411,7 @@ TEST ("dependencies_four") TEST ("dependencies_all") { lumiera_interfaceregistry_init (); - lumiera_interfaceregistry_bulkregister_interfaces (dependencytests(), NULL); + LUMIERA_INTERFACE_REGISTEREXPORTED; TRACE (tests, "OPEN one"); LUMIERA_INTERFACE_HANDLE(lumieraorg_testexample_void, 0) handle_one = @@ -450,7 +448,7 @@ TEST ("dependencies_all") lumiera_interface_close ((LumieraInterface)handle_one); - lumiera_interfaceregistry_bulkremove_interfaces (dependencytests()); + LUMIERA_INTERFACE_UNREGISTEREXPORTED; lumiera_interfaceregistry_destroy (); }