Isis 3 Programmer Reference
Plugin.cpp
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 #include "Plugin.h"
8 
9 #include <ostream>
10 
11 #include <QCoreApplication>
12 #include <QLibrary>
13 #include <QStringList>
14 
15 #include "FileName.h"
16 #include "IException.h"
17 
18 using namespace std;
19 
20 namespace Isis {
22  Plugin::Plugin() : Pvl() {
23  }
24 
39  QFunctionPointer Plugin::GetPlugin(const QString &group) {
40  // Get the library and plugin to load
41  PvlGroup &g = findGroup(group);
42  QString library = g["Library"];
43 
44  QString path = "./";
45  Isis::FileName libraryFile(path + library);
46 
47  QString pluginName = g["Routine"];
48 
49  // Open the library, resolve the routine name, and return the function
50  // address. The function will stay in memory until the application exists
51  // so the scope of lib does not matter.
52  QLibrary lib(libraryFile.expanded());
53  bool loadedOk = lib.load();
54 
55  if(!loadedOk) {
56  path = "$ISISROOT/lib/";
57  libraryFile = path + library;
58  }
59 
60  lib.setFileName(libraryFile.expanded());
61 
62  QFunctionPointer plugin = lib.resolve(pluginName.toLatin1().data());
63  if (plugin == 0) {
64  QString msg = "Unable to find plugin [" + pluginName +
65  "] in shared library [" + lib.fileName() + "]";
66  throw IException(IException::Unknown, msg, _FILEINFO_);
67  }
68 
69  return plugin;
70  }
71 } // end namespace isis
Isis::PvlObject::findGroup
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition: PvlObject.h:129
Isis::PvlObject::group
PvlGroup & group(const int index)
Return the group at the specified index.
Definition: PvlObject.cpp:452
Isis::FileName
File name manipulation and expansion.
Definition: FileName.h:100
Isis::IException::Unknown
@ Unknown
A type of error that cannot be classified as any of the other error types.
Definition: IException.h:118
Isis::Pvl
Container for cube-like labels.
Definition: Pvl.h:119
Isis::FileName::expanded
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition: FileName.cpp:196
Isis::PvlGroup
Contains multiple PvlContainers.
Definition: PvlGroup.h:41
Isis::Plugin::GetPlugin
QFunctionPointer GetPlugin(const QString &group)
This method returns a void pointer to a C function (i.e., the plugin) It does this by looking in itse...
Definition: Plugin.cpp:39
Isis::IException
Isis exception class.
Definition: IException.h:91
std
Namespace for the standard library.
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16