From dacd393fefeabafd1306533dd6c5a56e0ab347cc Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Sun, 27 Feb 2011 18:48:35 +0100 Subject: Initial commit --- TPlugin.cpp | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 TPlugin.cpp (limited to 'TPlugin.cpp') diff --git a/TPlugin.cpp b/TPlugin.cpp new file mode 100644 index 0000000..f3cbc48 --- /dev/null +++ b/TPlugin.cpp @@ -0,0 +1,87 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; +#include "TPlugin.h" +#include "main.h" + +#include "TConfig.h" +#include "TConfigReadOnly.h" + +TPlugin::TPlugin(string pluginname) +{ + string path; + plugininitfunc initfunc; + + path="./plugins/"+lcase(pluginname)+".so"; + handle=dlopen(path.c_str(),RTLD_NOW); + if (!handle) + { + cout << "file '" << "./plugins/"+lcase(pluginname)+".so" << "' not found. " << dlerror() << endl; + throw 1; + } + + func=(pluginfunc)dlsym(handle, "plugin"); + if (func==NULL) + { + cout << "symbol 'plugin' not found."<< endl; + dlclose(handle); handle=0; + throw 2; + } + + recv_msg=(pluginrecvfunc)dlsym(handle, "recv_message"); + if (recv_msg==NULL) + { + cout << "symbol 'recv_message' not found. this is not an error."<< endl; + } + + initfunc=(plugininitfunc)dlsym(handle,"init"); + if (initfunc==NULL) + { + cout << "symbol 'init' not found." << endl; + dlclose(handle); handle=0; + throw 3; + } + + (*initfunc) (&context_size, &default_flags_for_connections,&default_flags_for_channels,&default_flags_for_sessions); + + name=pluginname; +} + +TPlugin::~TPlugin() +{ + if (handle) + { + cout << "unloading '"<