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

Record plugin load failures

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