1 ////////////////////////////////////////////////////////////
\r
3 // Pluma - Plug-in Management Framework
\r
4 // Copyright (C) 2010-2012 Gil Costa (gsaurus@gmail.com)
\r
6 // This software is provided 'as-is', without any express or implied warranty.
\r
7 // In no event will the authors be held liable for any damages arising from the use of this software.
\r
9 // Permission is granted to anyone to use this software for any purpose,
\r
10 // including commercial applications, and to alter it and redistribute it freely,
\r
11 // subject to the following restrictions:
\r
13 // 1. The origin of this software must not be misrepresented;
\r
14 // you must not claim that you wrote the original software.
\r
15 // If you use this software in a product, an acknowledgment
\r
16 // in the product documentation would be appreciated but is not required.
\r
18 // 2. Altered source versions must be plainly marked as such,
\r
19 // and must not be misrepresented as being the original software.
\r
21 // 3. This notice may not be removed or altered from any source distribution.
\r
23 ////////////////////////////////////////////////////////////
\r
25 #ifndef PLUMA_PLUGIN_MANAGER_HPP
\r
26 #define PLUMA_PLUGIN_MANAGER_HPP
\r
28 ////////////////////////////////////////////////////////////
\r
30 ////////////////////////////////////////////////////////////
\r
31 #include <Pluma/Config.hpp>
\r
32 #include <Pluma/Host.hpp>
\r
40 ////////////////////////////////////////////////////////////
\r
41 /// \brief Manages loaded plugins.
\r
43 ////////////////////////////////////////////////////////////
\r
44 class PLUMA_API PluginManager{
\r
49 ////////////////////////////////////////////////////////////
\r
50 /// \brief Destructor.
\r
52 ////////////////////////////////////////////////////////////
\r
55 ////////////////////////////////////////////////////////////
\r
56 /// \brief Load a plugin given it's path
\r
58 /// \param path Path for the plugin, including plugin name. File extension
\r
59 /// may be included, but is discouraged for better cross platform code.
\r
60 /// If file extension isn't present on the path, Pluma will deduce it
\r
61 /// from the operating system.
\r
63 /// \return True if the plugin is successfully loaded.
\r
65 /// \see load(const std::string&, const std::string&)
\r
66 /// \see loadFromFolder
\r
70 ////////////////////////////////////////////////////////////
\r
71 bool load(const std::string& path);
\r
74 ////////////////////////////////////////////////////////////
\r
75 /// \brief Load a plugin from a given folder
\r
77 /// \param folder The folder path.
\r
78 /// \param pluginName Name of the plugin. File extension
\r
79 /// may be included, but is discouraged for better cross platform code.
\r
80 /// If file extension is omitted, Pluma will deduce it
\r
81 /// from the operating system.
\r
83 /// \return True if the plugin is successfully loaded.
\r
85 /// \see load(const std::string&)
\r
86 /// \see loadFromFolder
\r
90 ////////////////////////////////////////////////////////////
\r
91 bool load(const std::string& folder, const std::string& pluginName);
\r
93 ////////////////////////////////////////////////////////////
\r
94 /// \brief Load all plugins from a given folder
\r
96 /// \param folder Path for the folder where the plug-ins are.
\r
97 /// \param recursive If true it will search on sub-folders as well
\r
99 /// \return Number of successfully loaded plug-ins.
\r
101 /// \see load(const std::string&, const std::string&)
\r
102 /// \see load(const std::string&)
\r
106 ////////////////////////////////////////////////////////////
\r
107 std::list< std::string > loadFromFolder(
\r
108 const std::string& folder, bool recursive = false
\r
111 ////////////////////////////////////////////////////////////
\r
112 /// \brief Unload a plugin.
\r
114 /// \param pluginName Name or path of the plugin.
\r
116 /// \return True if the plugin is successfully unloaded,
\r
117 /// false if no such plugin exists on the manager.
\r
119 /// \see load(const std::string&, const std::string&)
\r
120 /// \see load(const std::string&)
\r
121 /// \see loadFromFolder
\r
124 ////////////////////////////////////////////////////////////
\r
125 bool unload(const std::string& pluginName);
\r
127 ////////////////////////////////////////////////////////////
\r
128 /// \brief Unload all loaded plugins.
\r
130 /// \see load(const std::string&, const std::string&)
\r
131 /// \see load(const std::string&)
\r
132 /// \see loadFromFolder
\r
135 ////////////////////////////////////////////////////////////
\r
138 ////////////////////////////////////////////////////////////
\r
139 /// \brief Directly add a new provider.
\r
141 /// \param provider Provider.
\r
143 ////////////////////////////////////////////////////////////
\r
144 bool addProvider(Provider* provider);
\r
146 ////////////////////////////////////////////////////////////
\r
147 /// \brief Get the name of all loaded plugins.
\r
149 /// \param pluginNames A vector to fill with the plugins names.
\r
151 ////////////////////////////////////////////////////////////
\r
152 void getLoadedPlugins(std::vector<const std::string*>& pluginNames) const;
\r
154 ////////////////////////////////////////////////////////////
\r
155 /// \brief Check if a plug-in is loaded.
\r
157 /// \param pluginName the plug-in tname o check.
\r
159 ////////////////////////////////////////////////////////////
\r
160 bool isLoaded(const std::string& pluginName) const;
\r
165 ////////////////////////////////////////////////////////////
\r
166 /// \brief Default constructor.
\r
168 /// PluginManager cannot be publicly instantiated.
\r
170 ////////////////////////////////////////////////////////////
\r
173 ////////////////////////////////////////////////////////////
\r
174 /// \brief Register a provider type
\r
176 /// \param type Provider type.
\r
177 /// \param version Current version of that provider type.
\r
178 /// \param lowestVersion Lowest compatible version of that provider type.
\r
180 /// \see Host::registerType
\r
182 ////////////////////////////////////////////////////////////
\r
183 void registerType(const std::string& type, unsigned int version, unsigned int lowestVersion);
\r
185 ////////////////////////////////////////////////////////////
\r
186 /// \brief Get providers of a certain type.
\r
188 /// \param type Provider type.
\r
190 /// \return Pointer to the list of providers of that \a type,
\r
191 /// or NULL if \a type is not registered.
\r
193 /// \see Host::getProviders
\r
195 ////////////////////////////////////////////////////////////
\r
196 const std::list<Provider*>* getProviders(const std::string& type) const;
\r
201 ////////////////////////////////////////////////////////////
\r
202 /// \brief Get the plugin name (without extension) from its path
\r
204 /// \param path Plugin path.
\r
206 /// \return Name of the plugin.
\r
208 /// \see resolvePathExtension
\r
209 /// \see load(const std::string&, const std::string&)
\r
210 /// \see load(const std::string&)
\r
213 ////////////////////////////////////////////////////////////
\r
214 static std::string getPluginName(const std::string& path);
\r
216 ////////////////////////////////////////////////////////////
\r
217 /// \brief If the plugin path omits it's extension, this method returns
\r
218 /// the path plus the OS specific dll extension.
\r
219 /// Return a copy of the path otherwise.
\r
221 /// \param path Plugin path.
\r
223 /// \return Path with extension.
\r
225 /// \see getPluginName
\r
226 /// \see load(const std::string&, const std::string&)
\r
227 /// \see load(const std::string&)
\r
230 ////////////////////////////////////////////////////////////
\r
231 static std::string resolvePathExtension(const std::string& path);
\r
236 /// Signature for the plugin's registration function
\r
237 typedef bool fnRegisterPlugin(Host&);
\r
238 typedef std::map<std::string,DLibrary*> LibMap;
\r
240 LibMap libraries; ///< Map containing the loaded libraries
\r
241 Host host; ///< Host app proxy, holding all providers
\r
245 } // namespace pluma
\r
247 #endif // PLUMA_PLUGIN_MANAGER_HPP
\r