Tulip  5.7.4
Large graphs analysis and drawing
PluginLibraryLoader.h
1 /*
2  *
3  * This file is part of Tulip (https://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. If a new version of a plugin exist in a user specific
81  * local directory then the plugin is not loaded.
82  *
83  *
84  * @param rootPath The root directory from which to look for plugins to load.
85  * @param loader A PluginLoader to output what is going on. Defaults to nullptr.
86  * @param userLocalPath A user specific local directory where some plugins may have been downloaded
87 
88  *
89  **/
90  static void loadPluginsFromDir(const std::string &rootPath, PluginLoader *loader = nullptr,
91  const std::string &userLocalPath = "");
92 
93  /**
94  * @brief Loads a single plugin library.
95  *
96  * @param filename The name of the plugin file to load.
97  * @param loader A loader to report what is going on (only its loaded or aborted functions will be
98  *called) Defaults to nullptr.
99  * @return bool Whether the plugin was successfully loaded.
100  **/
101  static bool loadPluginLibrary(const std::string &filename, PluginLoader *loader = nullptr);
102 #endif // EMSCRIPTEN
103 
104  /**
105  * @brief Gets the name of the plug-in library being loaded.
106  * If the plugin is statically linked into the tulip library, returns an empty string.
107  *
108  * @return :string& The name of the plugin library being loaded.
109  **/
110  static const std::string &getCurrentPluginFileName() {
111  return _currentPluginLibrary;
112  }
113 
114 private:
115  PluginLibraryLoader() {}
116 #ifndef EMSCRIPTEN
117  static bool initPluginDir(PluginLoader *loader, bool recursive = false,
118  const std::string &userPluginsPath = "");
119 #endif
120 
121  static std::string _message;
122  static std::string _pluginPath;
123  static std::string _currentPluginLibrary;
124 };
125 } // namespace tlp
126 
127 #endif // PLUGINLIBLOADER_H
128 
129 ///@endcond