1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems, Inc.
4
* Copyright (C) 2008 Sun Microsystems
6
6
* This program is free software; you can redistribute it and/or modify
7
7
* it under the terms of the GNU General Public License as published by
26
26
#include <algorithm>
29
#include <boost/scoped_ptr.hpp>
31
28
#include "drizzled/gettext.h"
32
29
#include "drizzled/unireg.h"
33
30
#include "drizzled/errmsg_print.h"
34
#include "drizzled/plugin/plugin.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;
47
std::map<std::string, Library *> library_map;
48
std::map<std::string, Module *> module_map;
49
std::map<std::string, plugin::Plugin *> plugin_registry;
64
56
Registry(const Registry&);
65
57
Registry& operator=(const Registry&);
71
61
static Registry& singleton()
85
73
void remove(Module *module);
87
std::vector<Module *> getList();
75
std::vector<Module *> getList(bool active);
89
const plugin::Plugin::map &getPluginsMap() const
77
const std::map<std::string, plugin::Plugin *> &getPluginsMap() const
91
79
return plugin_registry;
94
const ModuleMap &getModulesMap() const
82
const std::map<std::string, Module *> &getModulesMap() const
96
return module_registry_;
99
87
Library *addLibrary(const std::string &plugin_name, bool builtin= false);
106
94
void add(T *plugin)
108
96
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
97
std::string plugin_name(plugin->getName());
113
98
std::transform(plugin_name.begin(), plugin_name.end(),
114
99
plugin_name.begin(), ::tolower);
115
if (plugin_registry.find(std::make_pair(plugin_type, plugin_name)) != plugin_registry.end())
100
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());
102
errmsg_printf(ERRMSG_LVL_ERROR,
103
_("Loading plugin %s failed: a plugin by that name already "
104
"exists.\n"), plugin->getName().c_str());
124
107
if (T::addPlugin(plugin))
131
errmsg_printf(error::ERROR,
132
_("Fatal error: Failed initializing %s::%s plugin.\n"),
133
plugin->getTypeName().c_str(),
111
errmsg_printf(ERRMSG_LVL_ERROR,
112
_("Fatal error: Failed initializing %s plugin.\n"),
134
113
plugin->getName().c_str());
137
plugin_registry.insert(std::make_pair(std::make_pair(plugin_type, plugin_name), plugin));
116
plugin_registry.insert(std::pair<std::string, plugin::Plugin *>(plugin_name, plugin));
140
119
template<class T>
141
120
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
122
std::string plugin_name(plugin->getName());
147
123
std::transform(plugin_name.begin(), plugin_name.end(),
148
124
plugin_name.begin(), ::tolower);
149
125
T::removePlugin(plugin);
150
plugin_registry.erase(std::make_pair(plugin_type, plugin_name));
126
plugin_registry.erase(plugin_name);