Tulip  5.1.0
Large graphs analysis and drawing
PluginLibraryLoader.h
1 /*
2  *
3  * This file is part of Tulip (http://tulip.labri.fr)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 ///@cond DOXYGEN_HIDDEN
20 
21 #ifndef PLUGINLIBLOADER_H
22 #define PLUGINLIBLOADER_H
23 
24 #include <set>
25 #include <string>
26 
27 #include <tulip/tulipconf.h>
28 
29 namespace tlp {
30 
31 struct PluginLoader;
32 
33 /**
34  * @ingroup Plugins
35  *
36  * @brief This class takes care of the actual loading of the libraries.
37  * You can use it to load a single plugin (loadPluginLibrary) or all the plugins in a given folder (loadPlugins).
38  *
39  * It is a singleton to guarantee the currentPluginLibrary member is initialized, but it only shows static functions for syntactic sugar.
40  **/
41 class TLP_SCOPE PluginLibraryLoader {
42 public:
43 
44 #ifndef EMSCRIPTEN
45  /**
46  * @brief Loads all the plugins in each directory contained in TulipPluginsPath.
47  * This function will not look into subfolders of the specified folder.
48  *
49  *
50  * To load all the plugins in the following example, you need to call this function once for the lib/tulip folder,
51  * once for the glyph folder, and once for the interactors folder.
52  *
53  * lib/tulip/
54  * -> glyphs
55  * |-> libBillboard-4.0.0.so
56  * |-> libWindow-4.0.0.so
57  * -> interactors
58  * |-> libInteractorAddEdge-4.0.0.so
59  * |-> libInteractorSelectionModifier-4.0.0.so
60  * -> libAdjacencyMatrixImport-4.0.0.so
61  * -> libColorMapping-4.0.0.so
62  * -> libCompleteGraph-4.0.0.so
63  *
64  *
65  * @param loader A PluginLoader to output what is going on. Defaults to NULL.
66  * @param pluginPath A folder to append to each path in TulipPluginsPath (e.g. "glyphs/")
67  *
68  **/
69  static void loadPlugins(PluginLoader *loader = NULL, const std::string& pluginPath = "");
70 
71  /**
72  * @brief Recursively loads plugins from a root directory.
73  *
74  * @since Tulip 5.1
75  *
76  * This function enables to recursively load Tulip plugins from a
77  * provided root directory, thus visiting subdirectories of the provided
78  * one and so forth.
79  *
80  *
81  * @param rootPath The root directory from which to look for plugins to load.
82  * @param loader A PluginLoader to output what is going on. Defaults to NULL.
83 
84  *
85  **/
86  static void loadPluginsFromDir(const std::string& rootPath, PluginLoader *loader = NULL);
87 
88  /**
89  * @brief Loads a single plugin library.
90  *
91  * @param filename The name of the plugin file to load.
92  * @param loader A loader to report what is going on (only its loaded or aborted functions will be called) Defaults to NULL.
93  * @return bool Whether the plugin was sucessfully loaded.
94  **/
95  static bool loadPluginLibrary(const std::string & filename, PluginLoader *loader = NULL);
96 #endif //EMSCRIPTEN
97 
98  /**
99  * @brief Gets the name of the plug-in library being loaded.
100  * If the plugin is statically linked into the tulip library, returns an empty string.
101  *
102  * @return :string& The name of the plugin library being loaded.
103  **/
104  static const std::string& getCurrentPluginFileName() {
105  return getInstance()->currentPluginLibrary;
106  }
107 
108 private:
109  PluginLibraryLoader() {}
110 #ifndef EMSCRIPTEN
111  bool initPluginDir(PluginLoader *loader, bool recursive = false);
112 #endif
113 
114  static PluginLibraryLoader* getInstance() {
115  if(_instance == NULL) {
116  _instance = new PluginLibraryLoader();
117  }
118 
119  return _instance;
120  }
121  static PluginLibraryLoader* _instance;
122 
123  std::string message;
124  std::string pluginPath;
125  std::string currentPluginLibrary;
126 };
127 
128 }
129 
130 #endif //PLUGINLIBLOADER_H
131 
132 ///@endcond