diff options
author | Olliver Schinagl <oliver@schinagl.nl> | 2016-03-11 08:11:32 (GMT) |
---|---|---|
committer | Olliver Schinagl <oliver@schinagl.nl> | 2016-03-18 20:46:27 (GMT) |
commit | 32fb990072022f7668930473e07c3ae0eb3d8215 (patch) | |
tree | 79736e547aea85e597f403e24f84f06cb19c6541 /src/lib | |
parent | 6cd8ff8f7101091559fa60535cb26d7c30b23fdf (diff) | |
download | engagement-32fb990072022f7668930473e07c3ae0eb3d8215.zip engagement-32fb990072022f7668930473e07c3ae0eb3d8215.tar.gz engagement-32fb990072022f7668930473e07c3ae0eb3d8215.tar.bz2 |
Add initial plugin header
This patch adds the first preliminary draft plugin description. It is
missing many things, most importantly documentation.
More importantly it is likely not yet complete.
Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Makefile.am | 5 | ||||
-rw-r--r-- | src/lib/plugin.c | 74 |
2 files changed, 77 insertions, 2 deletions
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 0eaf568..fc64133 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -3,6 +3,7 @@ MAINTAINERCLEANFILES = Makefile.in AM_CPPFLAGS = \ -I$(top_srcdir)/src/lib \ -I$(top_builddir)/src/lib \ +-I$(top_srcdir)/src/include \ -DPACKAGE_LIB_DIR=\"$(libdir)\" \ -DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \ @EFL_CFLAGS@ \ @@ -13,6 +14,6 @@ lib_LTLIBRARIES = libengagement.la includes_HEADERS = engagement.h includesdir = $(includedir)/engagement-@VMAJ@ -libengagement_la_SOURCES = engagement.c -libengagement_la_LIBADD = @EFL_LIBS@ -lm +libengagement_la_SOURCES = engagement.c plugin.c +libengagement_la_LIBADD = @EFL_LIBS@ @LIBDL@ libengagement_la_LDFLAGS = @EFL_LTLIBRARY_FLAGS@ diff --git a/src/lib/plugin.c b/src/lib/plugin.c new file mode 100644 index 0000000..09df8de --- /dev/null +++ b/src/lib/plugin.c @@ -0,0 +1,74 @@ +/* + * (c) Copyright 2016 Olliver Schinagl + * Author: Olliver Schinagl <oliver@schinagl.nl> + * + * SPDX-License-Identifier: AGPL-3.0+ + */ + +#include <errno.h> +#include <stdlib.h> +#include <stdio.h> +#include <dlfcn.h> + +#include <engagement/plugin.h> + +struct plugin *plugin_load(const char *path) +{ + struct plugin *plugin; + void *handle; + + handle = dlopen(path, RTLD_LAZY); /* TODO check if RTLD_LAZY is what we want */ + if (!handle) { + // TODO EINA_LOG + fprintf(stderr, "dlopen failed: %s\n", dlerror()); + return NULL; + } + + /* TODO use macro's to allow for static inclusion */ + /* TODO use dlvsym() if available */ + plugin = (struct plugin *)dlsym(handle, PLUGIN_SYMBOL); + if(!plugin) { + // TODO EINA_LOG + fprintf(stderr, "dlsym failed%s\n", dlerror()); + return NULL; + } + + if (plugin->magic != PLUGIN_MAGIC) { + // TODO EINA_LOG + fprintf(stderr, "Failed to init plugin, magic mismatch, plugin corrupt?\n"); + return NULL; + } + plugin->_handle = handle; + + if (plugin->load) + plugin->load(); + + return plugin; +} + +int plugin_unload(struct plugin *plugin) +{ + int error; + + if (!plugin) { + // TODO EINA_LOG + fprintf(stderr, "Cannot unload plugin %p.\n", plugin); + return -EFAULT; + } + + if (plugin->unload) + plugin->unload(); + + if (!plugin->_handle) { + // TODO EINA_LOG + fprintf(stderr, "Error, no handle for plugin %s\n", + plugin->info.name); + return -EFAULT; + } + error = dlclose(plugin->_handle); + if (error) + // TODO EINA_LOG + fprintf(stderr, "Failed to close %s\n", dlerror()); + + return error; +} |