~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin_registry.h

  • Committer: Stewart Smith
  • Date: 2009-06-17 06:44:38 UTC
  • mto: This revision was merged to the branch mainline in revision 1094.
  • Revision ID: stewart@flamingspork.com-20090617064438-062owpgtdzgr4lvx
type_float.test for MyISAM as temp only

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#ifndef DRIZZLED_MODULE_REGISTRY_H
21
 
#define DRIZZLED_MODULE_REGISTRY_H
 
20
#ifndef DRIZZLED_PLUGIN_REGISTRY_H
 
21
#define DRIZZLED_PLUGIN_REGISTRY_H
 
22
 
22
23
 
23
24
#include <string>
24
25
#include <vector>
25
26
#include <map>
26
 
#include <algorithm>
27
 
 
28
 
#include "drizzled/gettext.h"
29
 
#include "drizzled/unireg.h"
30
 
#include "drizzled/errmsg_print.h"
31
 
#include "drizzled/plugin/plugin.h"
32
 
 
 
27
 
 
28
struct st_plugin_int;
 
29
class StorageEngine;
 
30
struct InfoSchemaTable;
 
31
class Function_builder;
 
32
class Logging_handler;
 
33
class Error_message_handler;
 
34
class Authentication;
 
35
class QueryCache;
 
36
class SchedulerFactory;
 
37
class ProtocolFactory;
33
38
namespace drizzled
34
39
{
35
 
 
36
 
namespace module
 
40
namespace plugin
37
41
{
38
 
class Module;
39
 
class Library;
 
42
class Replicator;
 
43
}
 
44
}
40
45
 
41
 
class Registry
 
46
class PluginRegistry
42
47
{
43
48
private:
44
 
  std::map<std::string, Library *> library_map;
45
 
  std::map<std::string, Module *> module_map;
46
 
  std::map<std::string, plugin::Plugin *> plugin_registry;
47
 
 
48
 
  Registry()
49
 
   : module_map(),
50
 
     plugin_registry()
51
 
  { }
52
 
 
53
 
  Registry(const Registry&);
54
 
  Registry& operator=(const Registry&);
55
 
  ~Registry();
 
49
  std::map<std::string, st_plugin_int *>
 
50
    plugin_map;
 
51
 
 
52
  PluginRegistry(const PluginRegistry&);
56
53
public:
57
 
 
58
 
  static Registry& singleton()
59
 
  {
60
 
    static Registry *registry= new Registry();
61
 
    return *registry;
62
 
  }
63
 
 
64
 
  void copy(plugin::Plugin::vector &arg);
65
 
 
66
 
  static void shutdown();
67
 
 
68
 
  Module *find(std::string name);
69
 
 
70
 
  void add(Module *module);
71
 
 
72
 
  void remove(Module *module);
73
 
 
74
 
  std::vector<Module *> getList(bool active);
75
 
 
76
 
  const std::map<std::string, plugin::Plugin *> &getPluginsMap() const
77
 
  {
78
 
    return plugin_registry;
79
 
  }
80
 
 
81
 
  const std::map<std::string, Module *> &getModulesMap() const
82
 
  {
83
 
    return module_map;
84
 
  }
85
 
 
86
 
  Library *addLibrary(const std::string &plugin_name, bool builtin= false);
87
 
  void removeLibrary(const std::string &plugin_name);
88
 
  Library *findLibrary(const std::string &plugin_name) const;
89
 
 
90
 
  void shutdownModules();
91
 
 
92
 
  template<class T>
93
 
  void add(T *plugin)
94
 
  {
95
 
    bool failed= false;
96
 
    std::string plugin_name(plugin->getName());
97
 
    std::transform(plugin_name.begin(), plugin_name.end(),
98
 
                   plugin_name.begin(), ::tolower);
99
 
    if (plugin_registry.find(plugin_name) != plugin_registry.end())
100
 
    {
101
 
      errmsg_printf(ERRMSG_LVL_ERROR,
102
 
                    _("Loading plugin %s failed: a plugin by that name already "
103
 
                      "exists.\n"), plugin->getName().c_str());
104
 
      failed= true;
105
 
    }
106
 
    if (T::addPlugin(plugin))
107
 
      failed= true;
108
 
    if (failed)
109
 
    {
110
 
      errmsg_printf(ERRMSG_LVL_ERROR,
111
 
                    _("Fatal error: Failed initializing %s plugin.\n"),
112
 
                    plugin->getName().c_str());
113
 
      unireg_abort(1);
114
 
    }
115
 
    plugin_registry.insert(std::pair<std::string, plugin::Plugin *>(plugin_name, plugin));
116
 
  }
117
 
 
118
 
  template<class T>
119
 
  void remove(T *plugin)
120
 
  {
121
 
    std::string plugin_name(plugin->getName());
122
 
    std::transform(plugin_name.begin(), plugin_name.end(),
123
 
                   plugin_name.begin(), ::tolower);
124
 
    T::removePlugin(plugin);
125
 
    plugin_registry.erase(plugin_name);
126
 
  }
127
 
 
 
54
  PluginRegistry() {}
 
55
 
 
56
 
 
57
  st_plugin_int *find(const LEX_STRING *name);
 
58
 
 
59
  void add(st_plugin_int *plugin);
 
60
 
 
61
  std::vector<st_plugin_int *> get_list(bool active);
 
62
  static PluginRegistry& getPluginRegistry();
 
63
 
 
64
  void add(StorageEngine *engine);
 
65
  void add(InfoSchemaTable *schema_table);
 
66
  void add(Function_builder *udf);
 
67
  void add(Logging_handler *handler);
 
68
  void add(Error_message_handler *handler);
 
69
  void add(Authentication *auth);
 
70
  void add(QueryCache *qcache);
 
71
  void add(SchedulerFactory *scheduler);
 
72
  void add(ProtocolFactory *protocol);
 
73
  void add(drizzled::plugin::Replicator *repl);
 
74
 
 
75
  void remove(StorageEngine *engine);
 
76
  void remove(InfoSchemaTable *schema_table);
 
77
  void remove(Function_builder *udf);
 
78
  void remove(Logging_handler *handler);
 
79
  void remove(Error_message_handler *handler);
 
80
  void remove(Authentication *auth);
 
81
  void remove(QueryCache *qcache);
 
82
  void remove(SchedulerFactory *scheduler);
 
83
  void remove(ProtocolFactory *protocol);
 
84
  void remove(drizzled::plugin::Replicator *repl);
128
85
 
129
86
};
130
87
 
131
 
} /* namespace module */
132
 
} /* namespace drizzled */
133
 
#endif /* DRIZZLED_MODULE_REGISTRY_H */
 
88
#endif /* DRIZZLED_PLUGIN_REGISTRY_H */