Isis 3.0 Object Programmers' Reference |
Home |
00001 00023 #include "Plugin.h" 00024 00025 #include <ostream> 00026 00027 #include <QCoreApplication> 00028 #include <QLibrary> 00029 #include <QStringList> 00030 00031 #include "FileName.h" 00032 #include "IException.h" 00033 00034 using namespace std; 00035 00036 namespace Isis { 00038 Plugin::Plugin() : Pvl() { 00039 } 00040 00055 void *Plugin::GetPlugin(const QString &group) { 00056 // Get the library and plugin to load 00057 PvlGroup &g = FindGroup(group); 00058 QString library = g["Library"]; 00059 00060 QString path = "./"; 00061 Isis::FileName libraryFile(path + library); 00062 00063 QString pluginName = g["Routine"]; 00064 00065 // Open the library, resolve the routine name, and return the function 00066 // address. The function will stay in memory until the application exists 00067 // so the scope of lib does not matter. 00068 QLibrary lib(libraryFile.expanded()); 00069 bool loadedOk = lib.load(); 00070 00071 if(!loadedOk) { 00072 path = "$ISISROOT/lib/"; 00073 libraryFile = path + library; 00074 } 00075 lib.setFileName(libraryFile.expanded()); 00076 00077 void *plugin = lib.resolve(pluginName.toAscii().data()); 00078 if(plugin == 0) { 00079 QString msg = "Unable to find plugin [" + pluginName + 00080 "] in shared library [" + lib.fileName() + "]"; 00081 throw IException(IException::Unknown, msg, _FILEINFO_); 00082 } 00083 00084 return plugin; 00085 } 00086 } // end namespace isis 00087