mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-28 05:36:00 +01:00
Add API versioning and add macro to register plugins.
If the plugin interface changes ZATHURA_API_VERSION has to be bumped before a release.
This commit is contained in:
parent
f659be99e7
commit
18b9694f9b
6 changed files with 83 additions and 7 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -12,3 +12,4 @@ zathura.pc
|
||||||
*.gcda
|
*.gcda
|
||||||
gcov/
|
gcov/
|
||||||
*.swp
|
*.swp
|
||||||
|
version.h
|
||||||
|
|
16
Makefile
16
Makefile
|
@ -28,6 +28,12 @@ options:
|
||||||
@echo "DFLAGS = ${DFLAGS}"
|
@echo "DFLAGS = ${DFLAGS}"
|
||||||
@echo "CC = ${CC}"
|
@echo "CC = ${CC}"
|
||||||
|
|
||||||
|
version.h: version.h.in config.mk
|
||||||
|
$(QUIET)sed 's/ZVMAJOR/${ZATHURA_VERSION_MAJOR}/' < version.h.in | \
|
||||||
|
sed 's/ZVMINOR/${ZATHURA_VERSION_MINOR}/' | \
|
||||||
|
sed 's/ZVREV/${ZATHURA_VERSION_REV}/' | \
|
||||||
|
sed 's/ZVAPI/${ZATHURA_API_VERSION}/' > version.h
|
||||||
|
|
||||||
%.o: %.c
|
%.o: %.c
|
||||||
$(ECHO) CC $<
|
$(ECHO) CC $<
|
||||||
@mkdir -p .depend
|
@mkdir -p .depend
|
||||||
|
@ -41,8 +47,8 @@ options:
|
||||||
# force recompilation of database.o if DATABASE has changed
|
# force recompilation of database.o if DATABASE has changed
|
||||||
database.o: database-${DATABASE}.o
|
database.o: database-${DATABASE}.o
|
||||||
|
|
||||||
${OBJECTS}: config.mk
|
${OBJECTS}: config.mk version.h
|
||||||
${DOBJECTS}: config.mk
|
${DOBJECTS}: config.mk version.h
|
||||||
|
|
||||||
${PROJECT}: ${OBJECTS}
|
${PROJECT}: ${OBJECTS}
|
||||||
$(ECHO) CC -o $@
|
$(ECHO) CC -o $@
|
||||||
|
@ -50,7 +56,8 @@ ${PROJECT}: ${OBJECTS}
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(QUIET)rm -rf ${PROJECT} ${OBJECTS} ${PROJECT}-${VERSION}.tar.gz \
|
$(QUIET)rm -rf ${PROJECT} ${OBJECTS} ${PROJECT}-${VERSION}.tar.gz \
|
||||||
${DOBJECTS} ${PROJECT}-debug .depend ${PROJECT}.pc doc *gcda *gcno $(PROJECT).info gcov
|
${DOBJECTS} ${PROJECT}-debug .depend ${PROJECT}.pc doc version.h \
|
||||||
|
*gcda *gcno $(PROJECT).info gcov
|
||||||
$(QUIET)make -C tests clean
|
$(QUIET)make -C tests clean
|
||||||
|
|
||||||
${PROJECT}-debug: ${DOBJECTS}
|
${PROJECT}-debug: ${DOBJECTS}
|
||||||
|
@ -62,6 +69,7 @@ debug: ${PROJECT}-debug
|
||||||
${PROJECT}.pc: ${PROJECT}.pc.in config.mk
|
${PROJECT}.pc: ${PROJECT}.pc.in config.mk
|
||||||
$(QUIET)echo project=${PROJECT} > ${PROJECT}.pc
|
$(QUIET)echo project=${PROJECT} > ${PROJECT}.pc
|
||||||
$(QUIET)echo version=${VERSION} >> ${PROJECT}.pc
|
$(QUIET)echo version=${VERSION} >> ${PROJECT}.pc
|
||||||
|
$(QUIET)echo apiversion=${ZATHHRA_API_VERSION} >> ${PROJECT}.pc
|
||||||
$(QUIET)echo includedir=${PREFIX}/include >> ${PROJECT}.pc
|
$(QUIET)echo includedir=${PREFIX}/include >> ${PROJECT}.pc
|
||||||
$(QUIET)echo plugindir=${PLUGINDIR} >> ${PROJECT}.pc
|
$(QUIET)echo plugindir=${PLUGINDIR} >> ${PROJECT}.pc
|
||||||
$(QUIET)echo GTK_VERSION=${ZATHURA_GTK_VERSION} >> ${PROJECT}.pc
|
$(QUIET)echo GTK_VERSION=${ZATHURA_GTK_VERSION} >> ${PROJECT}.pc
|
||||||
|
@ -82,7 +90,7 @@ dist: clean
|
||||||
$(QUIET)mkdir -p ${PROJECT}-${VERSION}/tests
|
$(QUIET)mkdir -p ${PROJECT}-${VERSION}/tests
|
||||||
$(QUIET)cp LICENSE Makefile config.mk common.mk README AUTHORS Doxyfile \
|
$(QUIET)cp LICENSE Makefile config.mk common.mk README AUTHORS Doxyfile \
|
||||||
${PROJECT}.1.rst ${PROJECT}rc.5.rst ${SOURCE} ${HEADER} ${PROJECT}.pc.in \
|
${PROJECT}.1.rst ${PROJECT}rc.5.rst ${SOURCE} ${HEADER} ${PROJECT}.pc.in \
|
||||||
${PROJECT}.desktop \
|
${PROJECT}.desktop version.h.in \
|
||||||
${PROJECT}-${VERSION}
|
${PROJECT}-${VERSION}
|
||||||
$(QUIET)cp tests/Makefile tests/config.mk tests/*.c \
|
$(QUIET)cp tests/Makefile tests/config.mk tests/*.c \
|
||||||
${PROJECT}-${VERSION}/tests
|
${PROJECT}-${VERSION}/tests
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
# See LICENSE file for license and copyright information
|
# See LICENSE file for license and copyright information
|
||||||
# zathura make config
|
# zathura make config
|
||||||
|
|
||||||
VERSION = 0.1.0
|
ZATHURA_VERSION_MAJOR = 0
|
||||||
|
ZATHURA_VERSION_MINOR = 1
|
||||||
|
ZATHURA_VERSION_REV = 0
|
||||||
|
ZATHURA_API_VERSION = 1
|
||||||
|
VERSION = ${ZATHURA_VERSION_MAJOR}.${ZATHURA_VERSION_MINOR}.${ZATHURA_VERSION_REV}
|
||||||
|
|
||||||
# the GTK version to use
|
# the GTK version to use
|
||||||
ZATHURA_GTK_VERSION ?= 2
|
ZATHURA_GTK_VERSION ?= 2
|
||||||
|
@ -29,7 +33,7 @@ SQLITE_LIB ?= $(shell pkg-config --libs sqlite3)
|
||||||
DL_LIB ?= -ldl
|
DL_LIB ?= -ldl
|
||||||
|
|
||||||
INCS = ${GIRARA_INC} ${GTK_INC}
|
INCS = ${GIRARA_INC} ${GTK_INC}
|
||||||
LIBS = ${GIRARA_LIB} ${GTK_LIB} $(DL_LIB) -lpthread -lm
|
LIBS = ${GIRARA_LIB} ${GTK_LIB} ${DL_LIB} -lpthread -lm
|
||||||
|
|
||||||
# flags
|
# flags
|
||||||
CFLAGS += -std=c99 -pedantic -Wall -Wno-format-zero-length -Wextra $(INCS)
|
CFLAGS += -std=c99 -pedantic -Wall -Wno-format-zero-length -Wextra $(INCS)
|
||||||
|
|
16
document.c
16
document.c
|
@ -87,7 +87,21 @@ zathura_document_plugins_load(zathura_t* zathura)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* resolve symbol */
|
/* resolve symbol and check API version*/
|
||||||
|
zathura_plugin_api_version_t api_version;
|
||||||
|
*(void**)(&api_version) = dlsym(handle, PLUGIN_API_VERSION_FUNCTION);
|
||||||
|
if (api_version != NULL) {
|
||||||
|
if (api_version() != ZATHURA_API_VERSION) {
|
||||||
|
girara_error("plugin %s has been built againt zathura with a different API version (plugin: %d, zathura: %d)",
|
||||||
|
path, api_version(), ZATHURA_API_VERSION);
|
||||||
|
g_free(path);
|
||||||
|
dlclose(handle);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
girara_warning("could not find '%s' function in plugin %s ... loading anyway", PLUGIN_API_VERSION_FUNCTION, path);
|
||||||
|
}
|
||||||
|
|
||||||
zathura_plugin_register_service_t register_plugin;
|
zathura_plugin_register_service_t register_plugin;
|
||||||
*(void**)(®ister_plugin) = dlsym(handle, PLUGIN_REGISTER_FUNCTION);
|
*(void**)(®ister_plugin) = dlsym(handle, PLUGIN_REGISTER_FUNCTION);
|
||||||
|
|
||||||
|
|
37
document.h
37
document.h
|
@ -9,8 +9,38 @@
|
||||||
|
|
||||||
#include <girara/types.h>
|
#include <girara/types.h>
|
||||||
#include "zathura.h"
|
#include "zathura.h"
|
||||||
|
#include "version.h"
|
||||||
|
|
||||||
#define PLUGIN_REGISTER_FUNCTION "plugin_register"
|
#define PLUGIN_REGISTER_FUNCTION "plugin_register"
|
||||||
|
#define PLUGIN_API_VERSION_FUNCTION "plugin_api_version"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a plugin.
|
||||||
|
*
|
||||||
|
* @param plugin_name the name of the plugin
|
||||||
|
* @param major the plugin's major version
|
||||||
|
* @param minor the plugin's minor version
|
||||||
|
* @param rev the plugin's revision
|
||||||
|
* @param plugin_open_function the plugin's open function
|
||||||
|
* @param mimetypes a char array of mime types supported by the plugin
|
||||||
|
*/
|
||||||
|
#define PLUGIN_REGISTER(plugin_name, major, minor, rev, plugin_open_function, mimetypes) \
|
||||||
|
unsigned int plugin_version_major() { return major; } \
|
||||||
|
unsigned int plugin_version_minor() { return minor; } \
|
||||||
|
unsigned int plugin_version_revision() { return rev; } \
|
||||||
|
unsigned int plugin_api_version() { return ZATHURA_API_VERSION; } \
|
||||||
|
\
|
||||||
|
void plugin_register(zathura_document_plugin_t* plugin) \
|
||||||
|
{ \
|
||||||
|
if (plugin == NULL) { \
|
||||||
|
return; \
|
||||||
|
} \
|
||||||
|
plugin->open_function = (plugin_open_function); \
|
||||||
|
static const char* mime_types[] = mimetypes; \
|
||||||
|
for (size_t s = 0; s != sizeof(mime_types) / sizeof(const char*); ++s) { \
|
||||||
|
girara_list_append(plugin->content_types, g_content_type_from_mime_type(mime_types[s])); \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error types for plugins
|
* Error types for plugins
|
||||||
|
@ -80,6 +110,13 @@ typedef struct zathura_password_dialog_info_s
|
||||||
*/
|
*/
|
||||||
typedef void (*zathura_plugin_register_service_t)(zathura_document_plugin_t*);
|
typedef void (*zathura_plugin_register_service_t)(zathura_document_plugin_t*);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function prototype that is called to get the plugin's API version.
|
||||||
|
*
|
||||||
|
* @return plugin's API version
|
||||||
|
*/
|
||||||
|
typedef unsigned int (*zathura_plugin_api_version_t)();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Image buffer
|
* Image buffer
|
||||||
*/
|
*/
|
||||||
|
|
12
version.h.in
Normal file
12
version.h.in
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
/* See LICENSE file for license and copyright information */
|
||||||
|
|
||||||
|
#ifndef ZATHURA_VERSION_H
|
||||||
|
#define ZATHURA_VERSION_H
|
||||||
|
|
||||||
|
#define ZATHURA_VERSION_MAJOR ZVMAJOR
|
||||||
|
#define ZATHUAR_VERSION_MINOR ZVMINOR
|
||||||
|
#define ZATHURA_VERSION_REV ZVREV
|
||||||
|
#define ZATHURA_VERSION "ZVMAJOR.ZVMINOR.ZVREV"
|
||||||
|
#define ZATHURA_API_VERSION ZVAPI
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue