Shinya Kitaoka 810553
#pragma once
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
Shinya Kitaoka 120a6e
class DVAPI TPluginInfo {
Shinya Kitaoka 120a6e
  std::string m_name;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TPluginInfo(std::string name = "") : m_name(name){};
Shinya Kitaoka 120a6e
  ~TPluginInfo(){};
Shinya Kitaoka 120a6e
  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
Shinya Kitaoka 120a6e
#define TLIBMAIN extern "C" __declspec(dllexport) const TPluginInfo *TLibMain()
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
#define TLIBMAIN extern "C" const TPluginInfo *TLibMain()
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TPluginManager {  // singleton
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  class Plugin;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  std::set<std::string> m_ignoreList;</std::string>
Shinya Kitaoka 120a6e
  typedef std::vector<const *="" plugin=""> PluginTable;</const>
Shinya Kitaoka 120a6e
  PluginTable m_pluginTable;
Shinya Kitaoka 120a6e
  std::set<tfilepath> m_loadedPlugins;</tfilepath>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TPluginManager();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  ~TPluginManager();
Shinya Kitaoka 120a6e
  static TPluginManager *instance();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // the name should be ignored? (name only; case insensitive. e.g. "tnzimage")
Shinya Kitaoka 120a6e
  bool isIgnored(std::string name) const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // set names to ignore; clear previous list
Shinya Kitaoka 120a6e
  void setIgnoredList(const std::set<std::string> &lst);</std::string>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // helper method.
Shinya Kitaoka 120a6e
  void setIgnored(std::string name) {
Shinya Kitaoka 120a6e
    std::set<std::string> lst;</std::string>
Shinya Kitaoka 120a6e
    lst.insert(name);
Shinya Kitaoka 120a6e
    setIgnoredList(lst);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // try to load plugin specified by fp; check if already loaded
Shinya Kitaoka 120a6e
  void loadPlugin(const TFilePath &fp);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // load all plugins in dir
Shinya Kitaoka 120a6e
  void loadPlugins(const TFilePath &dir);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // load all plugins in <bin>/plugins/io and <bin>/plugins/fx</bin></bin>
Shinya Kitaoka 120a6e
  void loadStandardPlugins();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // unload plugins (automatically called atexit)
Shinya Kitaoka 120a6e
  void unloadPlugins();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif