HMSBEAGLE  1.0.0
Plugin.h
1 
8 #ifndef __PLUGIN_H__
9 #define __PLUGIN_H__
10 
11 #ifdef HAVE_CONFIG_H
12 #include "libhmsbeagle/config.h"
13 #endif
14 
15 #include "libhmsbeagle/platform.h"
16 #include "libhmsbeagle/BeagleImpl.h"
17 #include "libhmsbeagle/plugin/SharedLibrary.h"
18 #include <memory>
19 #include <string>
20 #include <map>
21 #include <list>
22 
23 namespace beagle {
24 namespace plugin {
25 
30 class BEAGLE_DLLEXPORT Plugin
31 {
32  public:
33  Plugin() {}
34 
35  Plugin(const char* plugin_name, const char* plugin_type)
36  : m_plugin_name(plugin_name), m_plugin_type(plugin_type) {}
37 
38  virtual std::string pluginName() const{ return m_plugin_name; }
39  virtual std::string pluginType() const{ return m_plugin_type; }
40 
41  virtual const std::list<beagle::BeagleImplFactory*>& getBeagleFactories() const{ return beagleFactories; }
42  virtual const std::list<BeagleResource>& getBeagleResources() const{ return beagleResources; }
43 
44 protected:
45  std::list<beagle::BeagleImplFactory*> beagleFactories;
46  std::list<BeagleResource> beagleResources;
47  std::string m_plugin_name;
48  std::string m_plugin_type;
49 };
50 
51 typedef Plugin* (*plugin_init_func)(void);
52 
53 class BEAGLE_DLLEXPORT PluginManager
54 {
55  public:
56  static PluginManager& instance();
57 
58  Plugin* findPlugin(const char* name)
59  throw (SharedLibraryException);
60 
61  private:
62  struct PluginInfo {
63  SharedLibrary* m_library;
64  std::string m_library_name;
65  Plugin* m_plugin;
66 
67  ~PluginInfo() { delete m_plugin; delete m_library; }
68  PluginInfo() : m_library(0), m_plugin(0) {}
69  };
70  PluginManager() {}
71  static PluginManager* ms_instance;
72  std::map<std::string,PluginInfo* > m_plugin_map;
73  // ...
74 };
75 
76 } // namespace plugin
77 } // namespace beagle
78 
79 #endif // __PLUGIN_H__