simpler interfaces
This commit is contained in:
@ -22,21 +22,23 @@ static Pair *morse2ompcreator(LAMMPS *lmp)
|
||||
}
|
||||
|
||||
static lammpsplugin_t plugin;
|
||||
extern "C" void lammpsplugin_init(void *lmp, void *handle, lammpsplugin_regfunc register_plugin)
|
||||
extern "C" void lammpsplugin_init(void *lmp, void *handle, void *regfunc)
|
||||
{
|
||||
memset(&plugin,0,sizeof(lammpsplugin_t));
|
||||
plugin.version = LAMMPS_VERSION;
|
||||
plugin.style = "pair";
|
||||
plugin.name = "morse2";
|
||||
plugin.info = "Morse2 variant pair style v1.0";
|
||||
plugin.author = "Axel Kohlmeyer (akohlmey@gmail.com)";
|
||||
plugin.creator = (lammpsplugin_factory *) &morse2creator;
|
||||
plugin.handle = handle;
|
||||
register_plugin(&plugin,lmp);
|
||||
// register plain morse2 pair style
|
||||
lammpsplugin_regfunc register_plugin = (lammpsplugin_regfunc) regfunc;
|
||||
memset(&plugin,0,sizeof(lammpsplugin_t));
|
||||
plugin.version = LAMMPS_VERSION;
|
||||
plugin.style = "pair";
|
||||
plugin.name = "morse2";
|
||||
plugin.info = "Morse2 variant pair style v1.0";
|
||||
plugin.author = "Axel Kohlmeyer (akohlmey@gmail.com)";
|
||||
plugin.creator = (lammpsplugin_factory *) &morse2creator;
|
||||
plugin.handle = handle;
|
||||
register_plugin(&plugin,lmp);
|
||||
|
||||
plugin.style = "pair";
|
||||
plugin.name = "morse2/omp";
|
||||
plugin.info = "Morse2 variant pair style for OpenMP v1.0";
|
||||
plugin.creator = (lammpsplugin_factory *) &morse2ompcreator;
|
||||
register_plugin(&plugin,lmp);
|
||||
// also register morse2/omp pair style. only need to update changed fields
|
||||
plugin.name = "morse2/omp";
|
||||
plugin.info = "Morse2 variant pair style for OpenMP v1.0";
|
||||
plugin.creator = (lammpsplugin_factory *) &morse2ompcreator;
|
||||
register_plugin(&plugin,lmp);
|
||||
}
|
||||
|
||||
@ -31,12 +31,12 @@ extern "C" {
|
||||
} lammpsplugin_t;
|
||||
|
||||
typedef void (*lammpsplugin_regfunc)(lammpsplugin_t *, void *);
|
||||
typedef void (*lammpsplugin_initfunc)(void *, void *, lammpsplugin_regfunc);
|
||||
typedef void (*lammpsplugin_initfunc)(void *, void *, void *);
|
||||
|
||||
// prototype for initializer function required
|
||||
// to load a plugin; uses C bindings
|
||||
|
||||
void lammpsplugin_init(void *, void *, lammpsplugin_regfunc);
|
||||
void lammpsplugin_init(void *, void *, void *);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
#include "lammps.h"
|
||||
#include "modify.h"
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#ifdef _WIN32
|
||||
@ -28,14 +29,20 @@
|
||||
|
||||
namespace LAMMPS_NS
|
||||
{
|
||||
// store list of plugin information data for loaded styles
|
||||
static std::vector<lammpsplugin_t> pluginlist;
|
||||
// map of dso handles
|
||||
static std::map<void *, int> dso_refcounter;
|
||||
|
||||
void plugin_load(const char *file, void *ptr)
|
||||
// load DSO and call included registration function
|
||||
void plugin_load(const char *file, LAMMPS *lmp)
|
||||
{
|
||||
LAMMPS *lmp = (LAMMPS *)ptr;
|
||||
#if defined(WIN32)
|
||||
utils::logmesg(lmp,"Loading of plugins not supported on Windows yet\n");
|
||||
#else
|
||||
|
||||
// open DSO from given path
|
||||
|
||||
void *dso = dlopen(file,RTLD_NOW|RTLD_GLOBAL);
|
||||
if (dso == nullptr) {
|
||||
utils::logmesg(lmp,fmt::format("Loading of plugin from file {} failed: "
|
||||
@ -43,17 +50,23 @@ namespace LAMMPS_NS
|
||||
return;
|
||||
}
|
||||
|
||||
// look up lammpsplugin_init() function in DSO. must have C bindings.
|
||||
|
||||
void *initfunc = dlsym(dso,"lammpsplugin_init");
|
||||
if (initfunc == nullptr) {
|
||||
dlclose(dso);
|
||||
utils::logmesg(lmp,fmt::format("Symbol lookup failure in file {}\n",file));
|
||||
return;
|
||||
}
|
||||
((lammpsplugin_initfunc)(initfunc))(ptr,dso,&plugin_register);
|
||||
// dlclose(dso);
|
||||
|
||||
// call initializer function loaded from DSO and pass pointer to LAMMPS instance,
|
||||
// the DSO handle (for reference counting) and plugin registration function pointer
|
||||
|
||||
((lammpsplugin_initfunc)(initfunc))((void *)lmp, dso, (void *)&plugin_register);
|
||||
#endif
|
||||
}
|
||||
|
||||
// register new style from plugin with LAMMPS
|
||||
void plugin_register(lammpsplugin_t *plugin, void *ptr)
|
||||
{
|
||||
LAMMPS *lmp = (LAMMPS *)ptr;
|
||||
@ -99,10 +112,10 @@ namespace LAMMPS_NS
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void plugin_unload(const char *style, const char *name, void *ptr)
|
||||
|
||||
// remove plugin from given style table
|
||||
void plugin_unload(const char *style, const char *name, LAMMPS *lmp)
|
||||
{
|
||||
LAMMPS *lmp = (LAMMPS *)ptr;
|
||||
std::string pstyle = style;
|
||||
if (pstyle == "pair") {
|
||||
auto found = lmp->force->pair_map->find(name);
|
||||
|
||||
@ -18,12 +18,13 @@
|
||||
|
||||
namespace LAMMPS_NS
|
||||
{
|
||||
void plugin_load(const char *, void *);
|
||||
class LAMMPS;
|
||||
void plugin_load(const char *, LAMMPS *);
|
||||
void plugin_register(lammpsplugin_t *, void *);
|
||||
int plugin_get_num_plugins();
|
||||
const lammpsplugin_t *plugin_info(int);
|
||||
int plugin_find(const char *, const char *);
|
||||
void plugin_unload(const char *, const char *, void *);
|
||||
void plugin_unload(const char *, const char *, LAMMPS *);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user