Tulip  5.0.0
Large graphs analysis and drawing
PluginLibraryLoader.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
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).0
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 0.
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 Loads a single plugin library.
73  *
74  * @param filename The name of the plugin file to load.
75  * @param loader A loader to report what is going on (only its loaded or aborted functions will be called) Defaults to 0.
76  * @return bool Whether the plugin was sucessfully loaded.
77  **/
78  static bool loadPluginLibrary(const std::string & filename, PluginLoader *loader = NULL);
79 #endif //EMSCRIPTEN
80 
81  /**
82  * @brief Gets the name of the plug-in library being loaded.
83  * If the plugin is statically linked into the tulip library, returns an empty string.
84  *
85  * @return :string& The name of the plugin library being loaded.
86  **/
87  static const std::string& getCurrentPluginFileName() {
88  return getInstance()->currentPluginLibrary;
89  }
90 
91 private:
92  PluginLibraryLoader() {}
93 #ifndef EMSCRIPTEN
94  bool loadNextPluginLibrary(PluginLoader *loader);
95 
96  bool initPluginDir(PluginLoader *loader);
97 #endif
98 
99  static PluginLibraryLoader* getInstance() {
100  if(_instance == NULL) {
101  _instance = new PluginLibraryLoader();
102  }
103 
104  return _instance;
105  }
106  static PluginLibraryLoader* _instance;
107 
108  std::string message;
109  std::string pluginPath;
110  std::string currentPluginLibrary;
111 };
112 
113 }
114 
115 #endif //PLUGINLIBLOADER_H
116 
117 ///@endcond