Field3D

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.

239{
240
241}

◆ ~PluginLoader()

PluginLoader::~PluginLoader ( )

Destructor.

Definition at line 245 of file PluginLoader.cpp.

246{
247
248}

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.

253{
254 // Get environment variable
255 char *cptr = getenv("FIELD3D_DSO_PATH");
256 if (!cptr)
257 return;
258
259 std::string path = cptr;
260
261 // Split paths
262 std::vector<std::string> paths;
263 const std::string delimiters = ":";
264
265 tokenize(path, delimiters, paths);
266
267 // For each path
268 for (unsigned int i = 0; i < paths.size(); i++) {
269
270 // List the contents of the directory
271 std::vector<std::string> sos;
272 if (!getDirSos(sos,paths[i])) {
273 continue;
274 }
275
276 // Open each file
277 for (unsigned int j = 0; j < sos.size(); j++) {
278 std::string sofile = sos[j];
279
280 //First check to see if a plugin of the same name has already been loaded
281 const std::string pathDelimiter = "/";
282 std::vector<std::string> pluginName;
283 tokenize(sofile, pathDelimiter, pluginName);
284
285 bool pluginAlreadyLoaded = false;
286
287 for (unsigned int i = 0; i < ms_pluginsLoaded.size(); i++) {
288 if (pluginName.size() > 0) {
289 if (ms_pluginsLoaded[i] == pluginName[pluginName.size() - 1]) {
290 //This plugin has been loaded so look for another one
291 //std::cout << ms_pluginsLoaded[i] << " is already loaded\n";
292 pluginAlreadyLoaded = true;
293 break;
294 }
295 }
296 }
297
298 if (pluginAlreadyLoaded) {
299 continue;
300 }
301
302 if (pluginName.size() > 0) {
303 std::string lastName = pluginName[pluginName.size() -1];
304 ms_pluginsLoaded.push_back(lastName);
305 }
306
307 RegistrationFunc fptr;
308
309 fptr = findRegistrationFunc(sofile);
310 if (fptr) {
311 // Call the registration function
312 int res = (*fptr)(ClassFactory::singleton());
313 if (!res) {
315 "failed to init Field3D plugin " + sofile);
316 } else {
317 Msg::print("Initialized Field3D Plugin " + sofile);
318 }
319 }
320 }
321 }
322}
static RegistrationFunc findRegistrationFunc(const std::string &sofile)
FIELD3D_NAMESPACE_OPEN typedef int(* RegistrationFunc)(ClassFactory &)
bool getDirSos(std::vector< std::string > &sos, std::string &dir)
static ClassFactory & singleton()
}
static std::vector< std::string > ms_pluginsLoaded
List of plugins loaded.
@ SevWarning
Definition Log.h:68
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
staticprivate

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: