Blame view

src/Plugins/Plugin.hh 1.64 KB
fbe3c2bb   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#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