Commit b2e7d94e authored by Robert McGibbon's avatar Robert McGibbon
Browse files

Record plugin load failures

parent bca01957
......@@ -171,6 +171,10 @@ public:
* Get a registered Platform by index.
*/
static Platform& getPlatform(int index);
/**
* Get any failures caused during the last call to loadPluginsFromDirectory
*/
static std::vector<std::string> getLoadFailures();
/**
* Get the registered Platform with a particular name. If no Platform with that name has been
* registered, this throws an exception.
......@@ -233,8 +237,10 @@ private:
std::map<std::string, KernelFactory*> kernelFactories;
std::map<std::string, std::string> defaultProperties;
static std::vector<Platform*>& getPlatforms();
static std::vector<std::string> loadFailures;
};
} // namespace OpenMM
#endif /*OPENMM_PLATFORM_H_*/
......@@ -51,6 +51,9 @@
using namespace OpenMM;
using namespace std;
std::vector<std::string> Platform::loadFailures;
static int registerPlatforms() {
// Register the Platforms built into the main library. This should eventually be moved elsewhere.
......@@ -140,6 +143,10 @@ Platform& Platform::getPlatform(int index) {
throw OpenMMException("Invalid platform index");
}
std::vector<std::string> Platform::getLoadFailures() {
return loadFailures;
}
Platform& Platform::getPlatformByName(const string& name) {
for (int i = 0; i < getNumPlatforms(); i++)
if (getPlatform(i).getName() == name)
......@@ -196,8 +203,9 @@ static void* loadOneLibrary(const string& file) {
throw OpenMMException("Loading dynamic libraries is not supported on PNaCl");
#else
void *handle = dlopen(file.c_str(), RTLD_LAZY | RTLD_GLOBAL);
if (handle == NULL)
if (handle == NULL) {
throw OpenMMException("Error loading library "+file+": "+dlerror());
}
return handle;
#endif
}
......@@ -261,12 +269,14 @@ vector<string> Platform::loadPluginsFromDirectory(const string& directory) {
vector<void*> plugins;
#endif
vector<string> loadedLibraries;
loadFailures.resize(0);
for (unsigned int i = 0; i < files.size(); ++i) {
try {
plugins.push_back(loadOneLibrary(directory+dirSeparator+files[i]));
loadedLibraries.push_back(files[i]);
} catch (OpenMMException& ex) {
// Just ignore it.
loadFailures.push_back(ex.what());
}
}
initializePlugins(plugins);
......
......@@ -180,6 +180,7 @@ UNITS = {
("*", "getParticleMass") : ("unit.amu", ()),
("*", "getPlatform") : (None, ()),
("*", "getPlatformByName") : (None, ()),
("*", "getLoadFailures"): (None, ()),
("*", "getRandomNumberSeed") : (None, ()),
("*", "getReactionFieldDielectric") : (None, ()),
("*", "getSoluteDielectric") : (None, ()),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment