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

Added a new plugin loader

parent f19ff1e6
No related branches found
No related tags found
No related merge requests found
Pipeline #1389732 passed
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#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;
};
#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