20
20
#ifndef DRIZZLED_PLUGIN_REGISTRY_H
21
21
#define DRIZZLED_PLUGIN_REGISTRY_H
23
#include "drizzled/name_map.h"
28
28
#include "drizzled/gettext.h"
29
29
#include "drizzled/unireg.h"
30
#include "drizzled/errmsg_print.h"
41
std::map<std::string, Handle *> handle_map;
42
NameMap<const Plugin *> plugin_registry;
42
std::map<std::string, Module *> module_map;
43
std::map<std::string, const Plugin *> plugin_registry;
44
Handle *current_handle;
45
Module *current_module;
52
53
Registry(const Registry&);
68
Handle *find(const LEX_STRING *name);
70
void add(Handle *handle);
72
void setCurrentHandle(Handle *plugin)
74
current_handle= plugin;
77
void clearCurrentHandle()
82
std::vector<Handle *> getList(bool active);
69
Module *find(const LEX_STRING *name);
71
void add(Module *module);
73
void setCurrentModule(Module *module)
75
current_module= module;
78
void clearCurrentModule()
83
std::vector<Module *> getList(bool active);
85
const std::map<std::string, const Plugin *> &getPluginsMap() const
87
return plugin_registry;
85
91
void add(T *plugin)
87
plugin->setHandle(current_handle);
93
plugin->setModule(current_module);
88
94
bool failed= false;
89
if (plugin_registry.add(plugin))
95
std::string plugin_name(plugin->getName());
96
std::transform(plugin_name.begin(), plugin_name.end(),
97
plugin_name.begin(), ::tolower);
98
if (plugin_registry.find(plugin_name) != plugin_registry.end())
100
errmsg_printf(ERRMSG_LVL_ERROR,
101
_("Loading plugin %s failed: a plugin by that name already "
102
"exists."), plugin->getName().c_str());
91
105
if (T::addPlugin(plugin))
95
/* Can't use errmsg_printf here because we might be initializing the
96
* error_message plugin.
99
_("Fatal error: Failed initializing %s plugin."),
100
plugin->getName().c_str());
109
errmsg_printf(ERRMSG_LVL_ERROR,
110
_("Fatal error: Failed initializing %s plugin."),
111
plugin->getName().c_str());
114
plugin_registry.insert(std::pair<std::string, const Plugin *>(plugin_name, plugin));
105
117
template<class T>
106
118
void remove(T *plugin)
120
std::string plugin_name(plugin->getName());
121
std::transform(plugin_name.begin(), plugin_name.end(),
122
plugin_name.begin(), ::tolower);
108
123
T::removePlugin(plugin);
109
plugin_registry.remove(plugin);
124
plugin_registry.erase(plugin_name);