PluginManager.hpp
1 //
3 // Pluma - Plug-in Management Framework
4 // Copyright (C) 2010-2012 Gil Costa (gsaurus@gmail.com)
5 //
6 // This software is provided 'as-is', without any express or implied warranty.
7 // In no event will the authors be held liable for any damages arising from the use of this software.
8 //
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it freely,
11 // subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented;
14 // you must not claim that you wrote the original software.
15 // If you use this software in a product, an acknowledgment
16 // in the product documentation would be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source distribution.
22 //
24 
25 #ifndef PLUMA_PLUGIN_MANAGER_HPP
26 #define PLUMA_PLUGIN_MANAGER_HPP
27 
29 // Headers
31 #include <Pluma/Config.hpp>
32 #include <Pluma/Host.hpp>
33 
34 #include <string>
35 #include <map>
36 
37 namespace pluma{
38 class DLibrary;
39 
44 class PLUMA_API PluginManager{
45 
46 
47 public:
48 
53  ~PluginManager();
54 
71  bool load(const std::string& path);
72 
73 
91  bool load(const std::string& folder, const std::string& pluginName);
92 
107  int loadFromFolder(const std::string& folder, bool recursive = false);
108 
123  bool unload(const std::string& pluginName);
124 
134  void unloadAll();
135 
142  bool addProvider(Provider* provider);
143 
150  void getLoadedPlugins(std::vector<const std::string*>& pluginNames) const;
151 
158  bool isLoaded(const std::string& pluginName) const;
159 
160 
161 protected:
162 
169  PluginManager();
170 
181  void registerType(const std::string& type, unsigned int version, unsigned int lowestVersion);
182 
194  const std::list<Provider*>* getProviders(const std::string& type) const;
195 
196 
197 private:
198 
212  static std::string getPluginName(const std::string& path);
213 
229  static std::string resolvePathExtension(const std::string& path);
230 
231 
232 private:
233 
235  typedef bool fnRegisterPlugin(Host&);
236  typedef std::map<std::string,DLibrary*> LibMap;
237 
238  LibMap libraries;
239  Host host;
240 
241 };
242 
243 } // namespace pluma
244 
245 #endif // PLUMA_PLUGIN_MANAGER_HPP
Manages loaded plugins.
Interface to provide applications with objects from plugins.
Definition: Provider.hpp:42
Manages providers.
Definition: Host.hpp:44