17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#ifndef DRIZZLED_MODULE_REGISTRY_H
21
#define DRIZZLED_MODULE_REGISTRY_H
20
#ifndef DRIZZLED_PLUGIN_REGISTRY_H
21
#define DRIZZLED_PLUGIN_REGISTRY_H
26
26
#include <algorithm>
29
#include <boost/scoped_ptr.hpp>
31
#include <drizzled/gettext.h>
32
#include <drizzled/unireg.h>
33
#include <drizzled/errmsg_print.h>
34
#include <drizzled/plugin/plugin.h>
28
#include "drizzled/gettext.h"
29
#include "drizzled/unireg.h"
30
#include "drizzled/errmsg_print.h"
51
typedef std::map<std::string, Library *> LibraryMap;
52
typedef std::map<std::string, Module *> ModuleMap;
53
typedef std::vector<Module *> ModuleList;
55
LibraryMap library_registry_;
56
ModuleMap module_registry_;
57
boost::scoped_ptr<Graph> depend_graph_;
59
plugin::Plugin::map plugin_registry;
43
std::map<std::string, Library *> library_map;
44
std::map<std::string, Module *> module_map;
45
std::map<std::string, Plugin *> plugin_registry;
64
52
Registry(const Registry&);
65
53
Registry& operator=(const Registry&);
71
static Registry& singleton()
57
static plugin::Registry& singleton()
73
static Registry *registry= new Registry();
59
static plugin::Registry *registry= new plugin::Registry();
77
void copy(plugin::Plugin::vector &arg);
79
63
static void shutdown();
81
65
Module *find(std::string name);
83
67
void add(Module *module);
85
void remove(Module *module);
87
std::vector<Module *> getList();
89
const plugin::Plugin::map &getPluginsMap() const
70
std::vector<Module *> getList(bool active);
72
const std::map<std::string, Plugin *> &getPluginsMap() const
91
74
return plugin_registry;
94
const ModuleMap &getModulesMap() const
77
const std::map<std::string, Module *> &getModulesMap() const
96
return module_registry_;
99
Library *addLibrary(const std::string &plugin_name, bool builtin= false);
82
Library *addLibrary(const std::string &plugin_name);
100
83
void removeLibrary(const std::string &plugin_name);
101
84
Library *findLibrary(const std::string &plugin_name) const;
103
void shutdownModules();
106
87
void add(T *plugin)
108
89
bool failed= false;
109
std::string plugin_type(plugin->getTypeName());
110
std::transform(plugin_type.begin(), plugin_type.end(),
111
plugin_type.begin(), ::tolower);
112
90
std::string plugin_name(plugin->getName());
113
91
std::transform(plugin_name.begin(), plugin_name.end(),
114
92
plugin_name.begin(), ::tolower);
115
if (plugin_registry.find(std::make_pair(plugin_type, plugin_name)) != plugin_registry.end())
93
if (plugin_registry.find(plugin_name) != plugin_registry.end())
117
errmsg_printf(error::ERROR,
118
_("Loading plugin %s failed: a %s plugin by that name "
119
"already exists.\n"),
120
plugin->getTypeName().c_str(),
121
plugin->getName().c_str());
95
errmsg_printf(ERRMSG_LVL_ERROR,
96
_("Loading plugin %s failed: a plugin by that name already "
97
"exists.\n"), plugin->getName().c_str());
124
100
if (T::addPlugin(plugin))
131
errmsg_printf(error::ERROR,
132
_("Fatal error: Failed initializing %s::%s plugin.\n"),
133
plugin->getTypeName().c_str(),
104
errmsg_printf(ERRMSG_LVL_ERROR,
105
_("Fatal error: Failed initializing %s plugin.\n"),
134
106
plugin->getName().c_str());
137
plugin_registry.insert(std::make_pair(std::make_pair(plugin_type, plugin_name), plugin));
109
plugin_registry.insert(std::pair<std::string, Plugin *>(plugin_name, plugin));
140
112
template<class T>
141
113
void remove(T *plugin)
143
std::string plugin_type(plugin->getTypeName());
144
std::transform(plugin_type.begin(), plugin_type.end(),
145
plugin_type.begin(), ::tolower);
146
115
std::string plugin_name(plugin->getName());
147
116
std::transform(plugin_name.begin(), plugin_name.end(),
148
117
plugin_name.begin(), ::tolower);
149
118
T::removePlugin(plugin);
150
plugin_registry.erase(std::make_pair(plugin_type, plugin_name));
119
plugin_registry.erase(plugin_name);
156
} /* namespace module */
157
} /* namespace drizzled */
158
#endif /* DRIZZLED_MODULE_REGISTRY_H */
125
} /* end namespace plugin */
126
} /* end namespace drizzled */
127
#endif /* DRIZZLED_PLUGIN_REGISTRY_H */