Tulip  5.2.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
38  *(loadPlugins).
39  *
40  * It is a singleton to guarantee the currentPluginLibrary member is initialized, but it only shows
41  *static functions for syntactic sugar.
42  **/
43 class TLP_SCOPE PluginLibraryLoader {
44 public:
45 #ifndef EMSCRIPTEN
46  /**
47  * @brief Loads all the plugins in each directory contained in TulipPluginsPath.
48  * This function will not look into subfolders of the specified folder.
49  *
50  *
51  * To load all the plugins in the following example, you need to call this function once for the
52  *lib/tulip folder,
53  * once for the glyph folder, and once for the interactors folder.
54  *
55  * lib/tulip/
56  * -> glyphs
57  * |-> libBillboard-4.0.0.so
58  * |-> libWindow-4.0.0.so
59  * -> interactors
60  * |-> libInteractorAddEdge-4.0.0.so
61  * |-> libInteractorSelectionModifier-4.0.0.so
62  * -> libAdjacencyMatrixImport-4.0.0.so
63  * -> libColorMapping-4.0.0.so
64  * -> libCompleteGraph-4.0.0.so
65  *
66  *
67  * @param loader A PluginLoader to output what is going on. Defaults to nullptr.
68  * @param pluginPath A folder to append to each path in TulipPluginsPath (e.g. "glyphs/")
69  *
70  **/
71  static void loadPlugins(PluginLoader *loader = nullptr, const std::string &pluginPath = "");
72 
73  /**
74  * @brief Recursively loads plugins from a root directory.
75  *
76  * @since Tulip 5.1
77  *
78  * This function enables to recursively load Tulip plugins from a
79  * provided root directory, thus visiting subdirectories of the provided
80  * one and so forth.
81  *
82  *
83  * @param rootPath The root directory from which to look for plugins to load.
84  * @param loader A PluginLoader to output what is going on. Defaults to nullptr.
85 
86  *
87  **/
88  static void loadPluginsFromDir(const std::string &rootPath, PluginLoader *loader = nullptr);
89 
90  /**
91  * @brief Loads a single plugin library.
92  *
93  * @param filename The name of the plugin file to load.
94  * @param loader A loader to report what is going on (only its loaded or aborted functions will be
95  *called) Defaults to nullptr.
96  * @return bool Whether the plugin was sucessfully loaded.
97  **/
98  static bool loadPluginLibrary(const std::string &filename, PluginLoader *loader = nullptr);
99 #endif // EMSCRIPTEN
100 
101  /**
102  * @brief Gets the name of the plug-in library being loaded.
103  * If the plugin is statically linked into the tulip library, returns an empty string.
104  *
105  * @return :string& The name of the plugin library being loaded.
106  **/
107  static const std::string &getCurrentPluginFileName() {
108  return getInstance()->currentPluginLibrary;
109  }
110 
111 private:
112  PluginLibraryLoader() {}
113 #ifndef EMSCRIPTEN
114  bool initPluginDir(PluginLoader *loader, bool recursive = false);
115 #endif
116 
117  static PluginLibraryLoader *getInstance() {
118  if (_instance == nullptr) {
119  _instance = new PluginLibraryLoader();
120  }
121 
122  return _instance;
123  }
124  static PluginLibraryLoader *_instance;
125 
126  std::string message;
127  std::string pluginPath;
128  std::string currentPluginLibrary;
129 };
130 }
131 
132 #endif // PLUGINLIBLOADER_H
133 
134 ///@endcond