PluginLoader Class Reference
Classes and functions used to implement this library » Field IO classes under-the-hood

This class provides methods for loading Field plugins from disk. More...

`#include <PluginLoader.h>`

## Public Member Functions

| PluginLoader ()
| Default constructor.
| ~PluginLoader ()
| Destructor.

## Static Public Member Functions

static void | loadPlugins ()
| Checks all paths in $FIELD3D_DSO_PATH and loads the plugins it finds.

## Static Private Attributes

static std::vector< std::string > | ms_pluginsLoaded
| List of plugins loaded.

## Detailed Description

This class provides methods for loading Field plugins from disk.

Todo
  Look into adding maya-style single-plugin load and unload functions

Definition at line 68 of file PluginLoader.h.

## Constructor & Destructor Documentation

## PluginLoader()

PluginLoader::PluginLoader | ( |  | ) |

Default constructor.

Definition at line 238 of file PluginLoader.cpp.

{
}

## ~PluginLoader()

PluginLoader::~PluginLoader | ( |  | ) |

Destructor.

Definition at line 245 of file PluginLoader.cpp.

{
}

## Member Function Documentation

## loadPlugins()

void PluginLoader::loadPlugins | ( |  | ) |

static

Checks all paths in $FIELD3D_DSO_PATH and loads the plugins it finds.

Definition at line 252 of file PluginLoader.cpp.

{
// Get environment variable
char *cptr = getenv("FIELD3D_DSO_PATH");
if (!cptr)
return;
std::string path = cptr;
// Split paths
std::vector<std::string> paths;
const std::string delimiters = ":";
tokenize(path, delimiters, paths);
// For each path
for (unsigned int i = 0; i < paths.size(); i++) {
// List the contents of the directory
std::vector<std::string> sos;
if (!getDirSos(sos,paths[i])) {
continue;
}
// Open each file
for (unsigned int j = 0; j < sos.size(); j++) {
std::string sofile = sos[j];
//First check to see if a plugin of the same name has already been loaded
const std::string pathDelimiter = "/";
std::vector<std::string> pluginName;
tokenize(sofile, pathDelimiter, pluginName);
bool pluginAlreadyLoaded = false;
for (unsigned int i = 0; i < ms_pluginsLoaded.size(); i++) {
if (pluginName.size() > 0) {
if (ms_pluginsLoaded[i] == pluginName[pluginName.size() - 1]) {
//This plugin has been loaded so look for another one
//std::cout << ms_pluginsLoaded[i] << " is already loaded\n";
pluginAlreadyLoaded = true;
break;
}
}
}
if (pluginAlreadyLoaded) {
continue;
}
if (pluginName.size() > 0) {
std::string lastName = pluginName[pluginName.size() -1];
ms_pluginsLoaded.push_back(lastName);
}
RegistrationFunc fptr;
fptr = findRegistrationFunc(sofile);
if (fptr) {
// Call the registration function
int res = (*fptr)(ClassFactory::singleton());
if (!res) {
Msg::print(Msg::SevWarning,
"failed to init Field3D plugin " + sofile);
} else {
Msg::print("Initialized Field3D Plugin " + sofile);
}
}
}
}
}
findRegistrationFunc
static RegistrationFunc findRegistrationFunc(const std::string &sofile)
Definition PluginLoader.cpp:181
RegistrationFunc
FIELD3D_NAMESPACE_OPEN typedef int(* RegistrationFunc)(ClassFactory &)
Definition PluginLoader.cpp:92
getDirSos
bool getDirSos(std::vector< std::string > &sos, std::string &dir)
Definition PluginLoader.cpp:125
ClassFactory::singleton
static ClassFactory & singleton()
}
Definition ClassFactory.cpp:278
PluginLoader::ms_pluginsLoaded
static std::vector< std::string > ms_pluginsLoaded
List of plugins loaded.
Definition PluginLoader.h:96
Msg::SevWarning
@ SevWarning
Definition Log.h:68
Msg::print
FIELD3D_API void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity.
Definition Log.cpp:70

References findRegistrationFunc(), getDirSos(), ms_pluginsLoaded, Msg::print(), RegistrationFunc, Msg::SevWarning, and ClassFactory::singleton().

Referenced by ClassFactory::ClassFactory().

## Member Data Documentation

## ms_pluginsLoaded

std::vector< std::string > PluginLoader::ms_pluginsLoaded

static private

List of plugins loaded.

Definition at line 96 of file PluginLoader.h.

Referenced by loadPlugins().

The documentation for this class was generated from the following files:

- export/PluginLoader.h
- src/PluginLoader.cpp