1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
#include "drizzled/module/registry.h"
27
#include "drizzled/module/library.h"
29
#include "drizzled/plugin.h"
30
#include "drizzled/show.h"
31
#include "drizzled/cursor.h"
33
#include <boost/bind.hpp>
41
module::Registry::~Registry()
43
std::map<std::string, plugin::Plugin *>::iterator plugin_iter;
45
/* Give all plugins a chance to cleanup, before
46
* all plugins are deleted.
47
* This can be used if shutdown code references
50
plugin_iter= plugin_registry.begin();
51
while (plugin_iter != plugin_registry.end())
53
(*plugin_iter).second->shutdownPlugin();
57
plugin_iter= plugin_registry.begin();
58
while (plugin_iter != plugin_registry.end())
60
delete (*plugin_iter).second;
63
plugin_registry.clear();
66
@TODO When we delete modules here, we segfault on a bad string. Why?
67
map<string, module::Module *>::iterator module_iter= module_map.begin();
69
while (module_iter != module_map.end())
71
delete (*module_iter).second;
76
std::map<std::string, module::Library *>::iterator library_iter= library_map.begin();
77
while (library_iter != library_map.end())
79
delete (*library_iter).second;
85
void module::Registry::shutdown()
87
module::Registry& registry= singleton();
91
module::Module *module::Registry::find(std::string name)
93
std::transform(name.begin(), name.end(), name.begin(), ::tolower);
95
std::map<std::string, module::Module *>::iterator map_iter;
96
map_iter= module_map.find(name);
97
if (map_iter != module_map.end())
98
return (*map_iter).second;
102
void module::Registry::add(module::Module *handle)
104
std::string add_str(handle->getName());
105
transform(add_str.begin(), add_str.end(),
106
add_str.begin(), ::tolower);
108
module_map[add_str]= handle;
111
void module::Registry::remove(module::Module *handle)
113
std::string remove_str(handle->getName());
114
std::transform(remove_str.begin(), remove_str.end(),
115
remove_str.begin(), ::tolower);
117
module_map.erase(remove_str);
120
void module::Registry::copy(plugin::Plugin::vector &arg)
122
arg.reserve(plugin_registry.size());
124
std::transform(plugin_registry.begin(),
125
plugin_registry.end(),
126
std::back_inserter(arg),
127
boost::bind(&plugin::Plugin::map::value_type::second, _1) );
128
assert(arg.size() == plugin_registry.size());
131
vector<module::Module *> module::Registry::getList(bool active)
133
module::Module *plugin= NULL;
135
std::vector<module::Module *> plugins;
136
plugins.reserve(module_map.size());
138
std::map<std::string, module::Module *>::iterator map_iter;
139
for (map_iter= module_map.begin();
140
map_iter != module_map.end();
143
plugin= (*map_iter).second;
145
plugins.push_back(plugin);
146
else if (plugin->isInited)
147
plugins.push_back(plugin);
153
module::Library *module::Registry::addLibrary(const std::string &plugin_name,
157
/* If this dll is already loaded just return it */
158
module::Library *library= findLibrary(plugin_name);
164
library= module::Library::loadLibrary(plugin_name, builtin);
167
/* Add this dll to the map */
168
library_map.insert(make_pair(plugin_name, library));
174
void module::Registry::removeLibrary(const std::string &plugin_name)
176
std::map<std::string, module::Library *>::iterator iter=
177
library_map.find(plugin_name);
178
if (iter != library_map.end())
180
library_map.erase(iter);
181
delete (*iter).second;
185
module::Library *module::Registry::findLibrary(const std::string &plugin_name) const
187
std::map<std::string, module::Library *>::const_iterator iter=
188
library_map.find(plugin_name);
189
if (iter != library_map.end())
190
return (*iter).second;
194
void module::Registry::shutdownModules()
196
module_shutdown(*this);
199
} /* namespace drizzled */