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