From 1e1b55de576642509a5f36c882fd1c1a94ad2341 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Sat, 28 Apr 2012 21:26:10 +0200 Subject: [PATCH] Display plugin version in debug mode. --- plugin-api.h | 10 +++++----- plugin.c | 19 ++++++++++++++++--- plugin.h | 9 ++++++--- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/plugin-api.h b/plugin-api.h index 88ced6f..0954a67 100644 --- a/plugin-api.h +++ b/plugin-api.h @@ -45,11 +45,11 @@ void zathura_plugin_add_mimetype(zathura_plugin_t* plugin, const char* mime_type * @param mimetypes a char array of mime types supported by the plugin */ #define ZATHURA_PLUGIN_REGISTER(plugin_name, major, minor, rev, register_functions, mimetypes) \ - unsigned int zathura_plugin_version_major() { return major; } \ - unsigned int zathura_plugin_version_minor() { return minor; } \ - unsigned int zathura_plugin_version_revision() { return rev; } \ - unsigned int zathura_plugin_api_version() { return ZATHURA_API_VERSION; } \ - unsigned int zathura_plugin_abi_version() { return ZATHURA_ABI_VERSION; } \ + unsigned int zathura_plugin_version_major(void) { return major; } \ + unsigned int zathura_plugin_version_minor(void) { return minor; } \ + unsigned int zathura_plugin_version_revision(void) { return rev; } \ + unsigned int zathura_plugin_api_version(void) { return ZATHURA_API_VERSION; } \ + unsigned int zathura_plugin_abi_version(void) { return ZATHURA_ABI_VERSION; } \ \ void zathura_plugin_register(zathura_plugin_t* plugin) \ { \ diff --git a/plugin.c b/plugin.c index 68c879e..3197bb5 100644 --- a/plugin.c +++ b/plugin.c @@ -11,6 +11,8 @@ #include #include +typedef unsigned int (*zathura_plugin_version_t)(void); + /** * Plugin manager */ @@ -92,7 +94,8 @@ zathura_plugin_manager_load(zathura_plugin_manager_t* plugin_manager) /* resolve symbols and check API and ABI version*/ zathura_plugin_api_version_t api_version = NULL; - if (g_module_symbol(handle, PLUGIN_API_VERSION_FUNCTION, (gpointer*) &api_version) == FALSE || !api_version) + if (g_module_symbol(handle, PLUGIN_API_VERSION_FUNCTION, (gpointer*) &api_version) == FALSE || + api_version == NULL) { girara_error("could not find '%s' function in plugin %s", PLUGIN_API_VERSION_FUNCTION, path); g_free(path); @@ -109,7 +112,8 @@ zathura_plugin_manager_load(zathura_plugin_manager_t* plugin_manager) } zathura_plugin_abi_version_t abi_version = NULL; - if (g_module_symbol(handle, PLUGIN_ABI_VERSION_FUNCTION, (gpointer*) &abi_version) == FALSE || !abi_version) + if (g_module_symbol(handle, PLUGIN_ABI_VERSION_FUNCTION, (gpointer*) &abi_version) == FALSE || + abi_version == NULL) { girara_error("could not find '%s' function in plugin %s", PLUGIN_ABI_VERSION_FUNCTION, path); g_free(path); @@ -126,7 +130,8 @@ zathura_plugin_manager_load(zathura_plugin_manager_t* plugin_manager) } zathura_plugin_register_service_t register_service = NULL; - if (g_module_symbol(handle, PLUGIN_REGISTER_FUNCTION, (gpointer*) ®ister_service) == FALSE || !register_service) + if (g_module_symbol(handle, PLUGIN_REGISTER_FUNCTION, (gpointer*) ®ister_service) == FALSE || + register_service == NULL) { girara_error("could not find '%s' function in plugin %s", PLUGIN_REGISTER_FUNCTION, path); g_free(path); @@ -156,6 +161,14 @@ zathura_plugin_manager_load(zathura_plugin_manager_t* plugin_manager) zathura_plugin_free(plugin); } else { girara_info("successfully loaded plugin %s", path); + + zathura_plugin_version_t major = NULL, minor = NULL, rev = NULL; + g_module_symbol(handle, PLUGIN_VERSION_MAJOR_FUNCTION, (gpointer*) &major); + g_module_symbol(handle, PLUGIN_VERSION_MINOR_FUNCTION, (gpointer*) &minor); + g_module_symbol(handle, PLUGIN_VERSION_REVISION_FUNCTION, (gpointer*) &rev); + if (major != NULL && minor != NULL && rev != NULL) { + girara_debug("plugin '%s': version %u.%u.%u", path, major(), minor(), rev()); + } } g_free(path); diff --git a/plugin.h b/plugin.h index 795d398..abc08cc 100644 --- a/plugin.h +++ b/plugin.h @@ -11,9 +11,12 @@ #include "version.h" #include "zathura.h" -#define PLUGIN_REGISTER_FUNCTION "zathura_plugin_register" -#define PLUGIN_API_VERSION_FUNCTION "zathura_plugin_api_version" -#define PLUGIN_ABI_VERSION_FUNCTION "zathura_plugin_abi_version" +#define PLUGIN_REGISTER_FUNCTION "zathura_plugin_register" +#define PLUGIN_API_VERSION_FUNCTION "zathura_plugin_api_version" +#define PLUGIN_ABI_VERSION_FUNCTION "zathura_plugin_abi_version" +#define PLUGIN_VERSION_MAJOR_FUNCTION "zathura_plugin_version_major" +#define PLUGIN_VERSION_MINOR_FUNCTION "zathura_plugin_version_minor" +#define PLUGIN_VERSION_REVISION_FUNCTION "zathura_plugin_version_revision" /** * Document plugin structure