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

Record plugin load failures

parent bca01957
......@@ -49,13 +49,13 @@ class KernelFactory;
* More precisely, a Platform object acts as a registry for a set of KernelFactory
* objects which together implement the kernels. The Platform class, in turn, provides a
* static registry of all available Platform objects.
*
*
* To get a Platform object, call
*
*
* <pre>
* Platform& platform Platform::findPlatform(kernelNames);
* </pre>
*
*
* passing in the names of all kernels that will be required for the calculation you plan to perform. It
* will return the fastest available Platform which provides implementations of all the specified kernels.
* You can then call createKernel() to construct particular kernels as needed.
......@@ -133,14 +133,14 @@ public:
* Register a KernelFactory which should be used to create Kernels with a particular name.
* The Platform takes over ownership of the factory, and will delete it when the Platform itself
* is deleted.
*
*
* @param name the kernel name for which the factory should be used
* @param factory the factory to use for creating Kernels with the specified name
*/
void registerKernelFactory(const std::string& name, KernelFactory* factory);
/**
* Determine whether this Platforms provides implementations of a set of kernels.
*
*
* @param kernelNames the names of the kernels of interests
* @return true if this Platform provides implementations of all the kernels in the list,
* false if there are any which it does not support
......@@ -151,9 +151,9 @@ public:
* the returned Kernels are independent and do not interact with each other. This means
* that it is possible to have multiple simulations in progress at one time without them
* interfering.
*
*
* If no KernelFactory has been registered for the specified name, this will throw an exception.
*
*
* @param name the name of the Kernel to get
* @param context the context for which to create a Kernel
* @return a newly created Kernel object
......@@ -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.
......@@ -178,7 +182,7 @@ public:
static Platform& getPlatformByName(const std::string& name);
/**
* Find a Platform which can be used to perform a calculation.
*
*
* @param kernelNames the names of all kernels which will be needed for the calculation
* @return the fastest registered Platform which supports all of the requested kernels. If no
* Platform exists which supports all of them, this will throw 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