tahoma2d/toonz/sources/include/tpluginmanager.h

114 lines
2.3 KiB
C
Raw Normal View History

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