diff options
author | horchi <vdr@jwendel.de> | 2017-03-05 16:39:28 +0100 |
---|---|---|
committer | horchi <vdr@jwendel.de> | 2017-03-05 16:39:28 +0100 |
commit | e2a48d8701f91b8e24fbe9e99e91eb72a87bb749 (patch) | |
tree | 726f70554b4ca985a09ef6e30a7fdc8df089993c /plugin.c | |
download | vdr-epg-daemon-e2a48d8701f91b8e24fbe9e99e91eb72a87bb749.tar.gz vdr-epg-daemon-e2a48d8701f91b8e24fbe9e99e91eb72a87bb749.tar.bz2 |
git init1.1.103
Diffstat (limited to 'plugin.c')
-rw-r--r-- | plugin.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/plugin.c b/plugin.c new file mode 100644 index 0000000..7835e99 --- /dev/null +++ b/plugin.c @@ -0,0 +1,65 @@ +/* + * plugin.c + * + * See the README file for copyright information and how to reach the author. + * + */ + +#include <dlfcn.h> + +#include "epgd.h" + +//*************************************************************************** +// Class Plugin Loader +//*************************************************************************** + +PluginLoader::PluginLoader(const char* name, Plugin* p) +{ + fileName = strdup(name); + plugin = p; // normally 0, set for testing only + handle = 0; +} + +PluginLoader::~PluginLoader() +{ + delete plugin; + + if (handle) + dlclose(handle); + + free(fileName); +} + +int PluginLoader::load() +{ + const char* error; + + tell(0, "Loading plugin: %s", fileName); + + if (handle) + { + tell(0, "Warning: Attempt to load plugin '%s' twice!", fileName); + return fail; + } + + plugin = 0; + handle = dlopen(fileName, RTLD_NOW); + error = dlerror(); + + if (!error) + { + void *(*creator)(void); + + *(void**)(&creator) = dlsym(handle, "EPGPluginCreator"); + + error = dlerror(); + + if (!error) + plugin = (Plugin*)creator(); + } + + if (error) + tell(0, "Error: %s", error); + + return plugin ? success : fail; +} |