Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef TPLUGINMANAGER_INCLUDED
Toshihiro Shimizu 890ddd
#define TPLUGINMANAGER_INCLUDED
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// TPluginManager
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// usage example. Main program:
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//    TPluginManager::instance()->setIgnored("tnzimage");
Toshihiro Shimizu 890ddd
//    TPluginManager::instance()->loadStandardPlugins();
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// N.B. "tnzimagevector" is ignored by default
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// Plugin :
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//    TPluginInfo info("pluginName");
Toshihiro Shimizu 890ddd
//    TLIBMAIN
Toshihiro Shimizu 890ddd
//    {
Toshihiro Shimizu 890ddd
//       ....
Toshihiro Shimizu 890ddd
//       return &info;
Toshihiro Shimizu 890ddd
//    }
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//#include "tfilepath.h"
Toshihiro Shimizu 890ddd
#include "tcommon.h"
Toshihiro Shimizu 890ddd
#include <set></set>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TSYSTEM_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TFilePath;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TPluginInfo
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 3bfa54
	std::string m_name;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 3bfa54
	TPluginInfo(std::string name = "") : m_name(name){};
Toshihiro Shimizu 890ddd
	~TPluginInfo(){};
Shinya Kitaoka 3bfa54
	std::string getName() const { return m_name; };
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// L'entry point del plugin e' TLIBMAIN {....}
Toshihiro Shimizu 890ddd
//
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Toshihiro Shimizu 890ddd
#define TLIBMAIN                     \
Toshihiro Shimizu 890ddd
	extern "C" __declspec(dllexport) \
Toshihiro Shimizu 890ddd
		const TPluginInfo *          \
Toshihiro Shimizu 890ddd
		TLibMain()
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define TLIBMAIN \
Toshihiro Shimizu 890ddd
	extern "C" const TPluginInfo *TLibMain()
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TPluginManager
Toshihiro Shimizu 890ddd
{ // singleton
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	class Plugin;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
	std::set<std::string> m_ignoreList;</std::string>
Toshihiro Shimizu 890ddd
	typedef std::vector<const *="" plugin=""> PluginTable;</const>
Toshihiro Shimizu 890ddd
	PluginTable m_pluginTable;
Toshihiro Shimizu 890ddd
	std::set<tfilepath> m_loadedPlugins;</tfilepath>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPluginManager();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	~TPluginManager();
Toshihiro Shimizu 890ddd
	static TPluginManager *instance();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// the name should be ignored? (name only; case insensitive. e.g. "tnzimage")
Shinya Kitaoka 3bfa54
	bool isIgnored(std::string name) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// set names to ignore; clear previous list
Shinya Kitaoka 3bfa54
	void setIgnoredList(const std::set<std::string> &lst);</std::string>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// helper method.
Shinya Kitaoka 3bfa54
	void setIgnored(std::string name)
Toshihiro Shimizu 890ddd
	{
Shinya Kitaoka 3bfa54
		std::set<std::string> lst;</std::string>
Toshihiro Shimizu 890ddd
		lst.insert(name);
Toshihiro Shimizu 890ddd
		setIgnoredList(lst);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// try to load plugin specified by fp; check if already loaded
Toshihiro Shimizu 890ddd
	void loadPlugin(const TFilePath &fp);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// load all plugins in dir
Toshihiro Shimizu 890ddd
	void loadPlugins(const TFilePath &dir);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// load all plugins in <bin>/plugins/io and <bin>/plugins/fx</bin></bin>
Toshihiro Shimizu 890ddd
	void loadStandardPlugins();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// unload plugins (automatically called atexit)
Toshihiro Shimizu 890ddd
	void unloadPlugins();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif