PluginManager.hpp
00001 
00002 //
00003 // Pluma - Plug-in Management Framework
00004 // Copyright (C) 2010-2012 Gil Costa (gsaurus@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024 
00025 #ifndef PLUMA_PLUGIN_MANAGER_HPP
00026 #define PLUMA_PLUGIN_MANAGER_HPP
00027 
00029 // Headers
00031 #include <Pluma/Config.hpp>
00032 #include <Pluma/Host.hpp>
00033 
00034 #include <string>
00035 #include <map>
00036 
00037 namespace pluma{
00038 class DLibrary;
00039 
00044 class PLUMA_API PluginManager{
00045 
00046 
00047 public:
00048 
00053     ~PluginManager();
00054 
00071     bool load(const std::string& path);
00072 
00073 
00091     bool load(const std::string& folder, const std::string& pluginName);
00092 
00107     int loadFromFolder(const std::string& folder, bool recursive = false);
00108 
00123     bool unload(const std::string& pluginName);
00124 
00134     void unloadAll();
00135 
00142     bool addProvider(Provider* provider);
00143 
00150     void getLoadedPlugins(std::vector<const std::string*>& pluginNames) const;
00151 
00158     bool isLoaded(const std::string& pluginName) const;
00159 
00160 
00161 protected:
00162 
00169     PluginManager();
00170 
00181     void registerType(const std::string& type, unsigned int version, unsigned int lowestVersion);
00182 
00194     const std::list<Provider*>* getProviders(const std::string& type) const;
00195 
00196 
00197 private:
00198 
00212     static std::string getPluginName(const std::string& path);
00213 
00229     static std::string resolvePathExtension(const std::string& path);
00230 
00231 
00232 private:
00233 
00235     typedef bool fnRegisterPlugin(Host&);
00236     typedef std::map<std::string,DLibrary*> LibMap;
00237 
00238     LibMap libraries;   
00239     Host host;          
00240 
00241 };
00242 
00243 }   // namespace pluma
00244 
00245 #endif // PLUMA_PLUGIN_MANAGER_HPP