Plugin.hh 1.64 KB
#ifndef PLUGIN_PLUGIN_HH
#define PLUGIN_PLUGIN_HH

#include <string>
#include <dlfcn.h>

namespace AMDA {
namespace Plugins {

class PluginManager;

/// Signature for the version query function
typedef const char*  fnGetEngineVersion();

/// Signature for the plugin's registration and unregistration function
typedef void fnRegisterPlugin(PluginManager &);
typedef void fnUnregisterPlugin();

/// Representation of a plugin
class Plugin {
  public:
    /**
     * @brief Initialize and load plugin
     */
     Plugin(const std::string &sFilename);
    /// Copy existing plugin instance
     Plugin(const Plugin &Other);
    /**
     * @brief Unload a plugin
     */
     ~Plugin();

  // Get Methods
  void* getDLLHandle() const { return m_hDLL; }

  //
  // Plugin implementation
  //
  public:
    /// Query the plugin for its expected engine version
     const char* getPluginVersion() const {
      return m_pfnGetEngineVersion();
    }

  /// Register the plugin to a kernel
  void registerPlugin(PluginManager &K) {
    m_pfnRegisterPlugin(K);
  }

  private:
    /// Too lazy to this now...
    Plugin &operator =(const Plugin &Other);


    void               *m_hDLL;                ///< DLL handle
    size_t             *m_pDLLRefCount;        ///< Number of references to the DLL
    fnGetEngineVersion *m_pfnGetEngineVersion; ///< Version query function
    fnRegisterPlugin   *m_pfnRegisterPlugin;   ///< Plugin registration function
    fnUnregisterPlugin   *m_pfnUnregisterPlugin;   ///< Plugin unregistration function
    std::string         _filename;
};

typedef Plugin* PluginPtr;

} // namespace Plugins
} // namespace AMDA

#endif // PLUGIN_PLUGIN_HH