tahoma2d/toonz/sources/include/tpluginmanager.h

107 lines
2.3 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
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;
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class DVAPI TPluginInfo {
std::string m_name;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TPluginInfo(std::string name = "") : m_name(name){};
~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-06-15 18:43:10 +12:00
#define TLIBMAIN extern "C" __declspec(dllexport) const TPluginInfo *TLibMain()
2016-03-19 06:57:51 +13:00
#else
2016-06-15 18:43:10 +12:00
#define TLIBMAIN extern "C" const TPluginInfo *TLibMain()
2016-03-19 06:57:51 +13:00
#endif
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class DVAPI TPluginManager { // singleton
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
class Plugin;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
std::set<std::string> m_ignoreList;
typedef std::vector<const Plugin *> PluginTable;
PluginTable m_pluginTable;
std::set<TFilePath> m_loadedPlugins;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TPluginManager();
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
~TPluginManager();
static TPluginManager *instance();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// 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
2016-06-15 18:43:10 +12:00
// set names to ignore; clear previous list
void setIgnoredList(const std::set<std::string> &lst);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// helper method.
void setIgnored(std::string name) {
std::set<std::string> lst;
lst.insert(name);
setIgnoredList(lst);
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// try to load plugin specified by fp; check if already loaded
void loadPlugin(const TFilePath &fp);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// load all plugins in dir
void loadPlugins(const TFilePath &dir);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// load all plugins in <bin>/plugins/io and <bin>/plugins/fx
void loadStandardPlugins();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// unload plugins (automatically called atexit)
void unloadPlugins();
2016-03-19 06:57:51 +13:00
};
#endif