Tulip  4.4.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
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 1 and Inria Bordeaux - Sud Ouest
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 
20 #ifndef PLUGINLIBLOADER_H
21 #define PLUGINLIBLOADER_H
22 
23 #ifndef DOXYGEN_NOTFOR_USER
24 
25 #include <set>
26 #include <string>
27 
28 #include <tulip/tulipconf.h>
29 
30 namespace tlp {
31 
32 struct PluginLoader;
33 
34 /**
35  * @ingroup Plugins
36  *
37  * @brief This class takes care of the actual loading of the libraries.
38  * You can use it to load a single plugin (loadPluginLibrary) or all the plugins in a given folder (loadPlugins).0
39  *
40  * It is a singleton to guarantee the currentPluginLibrary member is initialized, but it only shows static functions for syntactic sugar.
41  **/
42 class TLP_SCOPE PluginLibraryLoader {
43 public:
44 
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 lib/tulip folder,
52  * once for the glyph folder, and once for the interactors folder.
53  *
54  * lib/tulip/
55  * -> glyphs
56  * |-> libBillboard-4.0.0.so
57  * |-> libWindow-4.0.0.so
58  * -> interactors
59  * |-> libInteractorAddEdge-4.0.0.so
60  * |-> libInteractorSelectionModifier-4.0.0.so
61  * -> libAdjacencyMatrixImport-4.0.0.so
62  * -> libColorMapping-4.0.0.so
63  * -> libCompleteGraph-4.0.0.so
64  *
65  *
66  * @param loader A PluginLoader to output what is going on. Defaults to 0.
67  * @param pluginPath A folder to append to each path in TulipPluginsPath (e.g. "glyphs/")
68  *
69  **/
70  static void loadPlugins(PluginLoader *loader = NULL, std::string pluginPath = "");
71 
72  /**
73  * @brief Loads a single plugin library.
74  *
75  * @param filename The name of the plugin file to load.
76  * @param loader A loader to report what is going on (only its loaded or aborted functions will be called) Defaults to 0.
77  * @return bool Whether the plugin was sucessfully loaded.
78  **/
79  static bool loadPluginLibrary(const std::string & filename, PluginLoader *loader = NULL);
80 #endif //EMSCRIPTEN
81 
82  /**
83  * @brief Gets the name of the plug-in library being loaded.
84  * If the plugin is statically linked into the tulip library, returns an empty string.
85  *
86  * @return :string& The name of the plugin library being loaded.
87  **/
88  static const std::string& getCurrentPluginFileName() {
89  return getInstance()->currentPluginLibrary;
90  }
91 
92 private:
94 #ifndef EMSCRIPTEN
95  bool loadNextPluginLibrary(PluginLoader *loader);
96 
97  bool initPluginDir(PluginLoader *loader);
98 #endif
99 
100  static PluginLibraryLoader* getInstance() {
101  if(_instance == NULL) {
102  _instance = new PluginLibraryLoader();
103  }
104 
105  return _instance;
106  }
107  static PluginLibraryLoader* _instance;
108 
109  std::string message;
110  std::string pluginPath;
111  std::string currentPluginLibrary;
112 };
113 
114 }
115 #endif //DOXYGEN_NOTFOR_USER
116 #endif //PLUGINLIBLOADER_H