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"
39
module::Registry::~Registry()
41
map<string, plugin::Plugin *>::iterator plugin_iter;
43
/* Give all plugins a chance to cleanup, before
44
* all plugins are deleted.
45
* This can be used if shutdown code references
48
plugin_iter= plugin_registry.begin();
49
while (plugin_iter != plugin_registry.end())
51
(*plugin_iter).second->shutdownPlugin();
55
plugin_iter= plugin_registry.begin();
56
while (plugin_iter != plugin_registry.end())
58
delete (*plugin_iter).second;
61
plugin_registry.clear();
64
@TODO When we delete modules here, we segfault on a bad string. Why?
65
map<string, module::Module *>::iterator module_iter= module_map.begin();
66
while (module_iter != module_map.end())
68
delete (*module_iter).second;
73
map<string, module::Library *>::iterator library_iter= library_map.begin();
74
while (library_iter != library_map.end())
76
delete (*library_iter).second;
82
void module::Registry::shutdown()
84
module::Registry& registry= singleton();
88
module::Module *module::Registry::find(string name)
90
transform(name.begin(), name.end(), name.begin(), ::tolower);
92
map<string, module::Module *>::iterator map_iter;
93
map_iter= module_map.find(name);
94
if (map_iter != module_map.end())
95
return (*map_iter).second;
99
void module::Registry::add(module::Module *handle)
101
string add_str(handle->getName());
102
transform(add_str.begin(), add_str.end(),
103
add_str.begin(), ::tolower);
105
module_map[add_str]= handle;
108
void module::Registry::remove(module::Module *handle)
110
string remove_str(handle->getName());
111
transform(remove_str.begin(), remove_str.end(),
112
remove_str.begin(), ::tolower);
114
module_map.erase(remove_str);
117
vector<module::Module *> module::Registry::getList(bool active)
119
module::Module *plugin= NULL;
121
vector<module::Module *> plugins;
122
plugins.reserve(module_map.size());
124
map<string, module::Module *>::iterator map_iter;
125
for (map_iter= module_map.begin();
126
map_iter != module_map.end();
129
plugin= (*map_iter).second;
131
plugins.push_back(plugin);
132
else if (plugin->isInited)
133
plugins.push_back(plugin);
139
module::Library *module::Registry::addLibrary(const string &plugin_name,
143
/* If this dll is already loaded just return it */
144
module::Library *library= findLibrary(plugin_name);
150
library= module::Library::loadLibrary(plugin_name, builtin);
153
/* Add this dll to the map */
154
library_map.insert(make_pair(plugin_name, library));
160
void module::Registry::removeLibrary(const string &plugin_name)
162
map<string, module::Library *>::iterator iter=
163
library_map.find(plugin_name);
164
if (iter != library_map.end())
166
library_map.erase(iter);
167
delete (*iter).second;
171
module::Library *module::Registry::findLibrary(const string &plugin_name) const
173
map<string, module::Library *>::const_iterator iter=
174
library_map.find(plugin_name);
175
if (iter != library_map.end())
176
return (*iter).second;
180
void module::Registry::shutdownModules()
182
module_shutdown(*this);
185
} /* namespace drizzled */