Skip to content
Snippets Groups Projects
Commit 842d35e0 authored by Joseph Boudreau's avatar Joseph Boudreau
Browse files

Plugin loaders are not instantiated from a new parameterized class,...

Plugin loaders are not instantiated from a new parameterized class, GeoPluginLoader, which does the work and which can load any type of properly prepared plugin.
parent d7d2bae2
No related branches found
No related tags found
No related merge requests found
......@@ -4,26 +4,6 @@
#ifndef GEOGEOMETRYPLUGINLOADER_H_
#define GEOGEOMETRYPLUGINLOADER_H_
#include <string>
class GeoVGeometryPlugin;
class GeoGeometryPluginLoader
{
public:
// Constructor:
GeoGeometryPluginLoader();
// Destructor:
~GeoGeometryPluginLoader();
// load Geometry plugin
GeoVGeometryPlugin *load(const std::string & path) const;
private:
GeoGeometryPluginLoader(const GeoGeometryPluginLoader &)=delete;
GeoGeometryPluginLoader & operator=(const GeoGeometryPluginLoader &)=delete;
};
#include "GeoModelKernel/GeoPluginLoader.h"
typedef GeoPluginLoader<GeoVGeometryPlugin> GeoGeometryPluginLoader;
#endif
#include "GeoModelKernel/GeoGeometryPluginLoader.h"
#include "GeoModelKernel/GeoVGeometryPlugin.h"
#include <string>
#include <iostream>
#include <dlfcn.h>
#include <libgen.h>
GeoGeometryPluginLoader::GeoGeometryPluginLoader () {
}
GeoGeometryPluginLoader::~GeoGeometryPluginLoader () {
}
GeoVGeometryPlugin *GeoGeometryPluginLoader::load(const std::string & pString) const {
std::string bNameString=basename ((char *) pString.c_str()); // Strip off the directory
bNameString=bNameString.substr(3); // Strip off leading "lib"
bNameString=bNameString.substr(0,bNameString.find(".")); // Strip off extensions
std::string createFunctionName = std::string("create")+bNameString;
//
// Loads the library:
//
void *handle = dlopen(pString.c_str(),RTLD_NOW);
if (!handle) {
std::cerr << dlerror() << std::endl;
return nullptr;
}
//
// Gets the function
//
void *f = dlsym(handle,createFunctionName.c_str());
if (!f) {
std::cerr << dlerror() << std::endl;
return nullptr;
}
typedef void * (*CreationMethod) ();
CreationMethod F = (CreationMethod) f;
//
//
//
GeoVGeometryPlugin * factory = (GeoVGeometryPlugin *) F();
return factory;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment