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= plugin_registry.begin();
42
while (plugin_iter != plugin_registry.end())
44
delete (*plugin_iter).second;
47
plugin_registry.clear();
50
@TODO When we delete modules here, we segfault on a bad string. Why?
51
map<string, module::Module *>::iterator module_iter= module_map.begin();
52
while (module_iter != module_map.end())
54
delete (*module_iter).second;
59
map<string, module::Library *>::iterator library_iter= library_map.begin();
60
while (library_iter != library_map.end())
62
delete (*library_iter).second;
68
void module::Registry::shutdown()
70
module::Registry& registry= singleton();
74
module::Module *module::Registry::find(string name)
76
transform(name.begin(), name.end(), name.begin(), ::tolower);
78
map<string, module::Module *>::iterator map_iter;
79
map_iter= module_map.find(name);
80
if (map_iter != module_map.end())
81
return (*map_iter).second;
85
void module::Registry::add(module::Module *handle)
87
string add_str(handle->getName());
88
transform(add_str.begin(), add_str.end(),
89
add_str.begin(), ::tolower);
91
module_map[add_str]= handle;
95
vector<module::Module *> module::Registry::getList(bool active)
97
module::Module *plugin= NULL;
99
vector<module::Module *> plugins;
100
plugins.reserve(module_map.size());
102
map<string, module::Module *>::iterator map_iter;
103
for (map_iter= module_map.begin();
104
map_iter != module_map.end();
107
plugin= (*map_iter).second;
109
plugins.push_back(plugin);
110
else if (plugin->isInited)
111
plugins.push_back(plugin);
117
module::Library *module::Registry::addLibrary(const string &plugin_name,
121
/* If this dll is already loaded just return it */
122
module::Library *library= findLibrary(plugin_name);
128
library= module::Library::loadLibrary(plugin_name, builtin);
131
/* Add this dll to the map */
132
library_map.insert(make_pair(plugin_name, library));
138
void module::Registry::removeLibrary(const string &plugin_name)
140
map<string, module::Library *>::iterator iter=
141
library_map.find(plugin_name);
142
if (iter != library_map.end())
144
library_map.erase(iter);
145
delete (*iter).second;
149
module::Library *module::Registry::findLibrary(const string &plugin_name) const
151
map<string, module::Library *>::const_iterator iter=
152
library_map.find(plugin_name);
153
if (iter != library_map.end())
154
return (*iter).second;
158
void module::Registry::shutdownModules()
160
module_shutdown(*this);
163
} /* namespace drizzled */