PluginManager.hh 1.76 KB
#ifndef PLUGIN_PLUGINMANAGER_HH
#define PLUGIN_PLUGINMANAGER_HH

#include <string>
#include <map>
#include <dsgpatt_Singleton.hh>
#include <log4cxx/logger.h>

#include <AMDA_exception.hh>
#include "Plugin.hh"

namespace AMDA {
namespace Plugins {

/**
 * logger definition
 */
extern log4cxx::LoggerPtr gLogger;
/**
 * Exception specific for AMDA::XMLParameterConfigurator module
 */
struct exception: virtual AMDA_exception { };

/**
 * Class PluginManager
 * Description : Manage plugin loading
 */
class PluginManager: public Singleton<PluginManager> {

public:
	// Design pattern
	friend class Singleton<PluginManager> ;

	/**
	 Loads 'path/PluginName' plugin
	 */
	void loadPlugin(const std::string &path, const std::string &sPluginName);

	/**
	 Loads a plugin which match with: ${sPluginName}/lib/{sPluginName}.so
	 */
	void loadPlugin(const std::string &sPluginName);


	/**
	 Attempt to load all libraries which match with this pattern '.so'
	 */
	void loadPluginFromPath(const std::string& pluginsPath);

	void loadPluginFromConfigFile(const char* fileName);


	/**
	 Get a reference to the list of Plugins
	 */
	inline const std::map<std::string, Plugin>& getALLPluginLoaded() {
		return _loadedPlugins;
	}

	void registerPlugin(const std::string &pluginName,
			const std::string &pluginPath);

protected:

	/**
	 Constructor (default one)
	 */
	PluginManager() {
	}

	/**
	 Copy Constructor (normally should not be used)
	 */
//	PluginManager(const PluginManager& /*copied*/) {
//	}

	/**
	 Destructor
	 */
	virtual ~PluginManager() {
	}

private:
	/// Map of plugins by their associated file names
	typedef std::map<std::string, Plugin> PluginMap;
	PluginMap _loadedPlugins;  ///< All plugins currently loaded
};

} // namespace Plugins
} // namespace AMDA

#endif // PLUGIN_PLUGINMANAGER_HH