908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
1999.6.1
by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file |
4 |
* Copyright (C) 2008 Sun Microsystems, Inc.
|
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
5 |
*
|
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.
|
|
9 |
*
|
|
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.
|
|
14 |
*
|
|
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
|
|
18 |
*/
|
|
19 |
||
1241.9.36
by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h. |
20 |
#include "config.h" |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
21 |
|
22 |
#include <string> |
|
23 |
#include <vector> |
|
24 |
#include <map> |
|
25 |
||
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
26 |
#include "drizzled/module/registry.h" |
27 |
#include "drizzled/module/library.h" |
|
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
28 |
|
29 |
#include "drizzled/plugin.h" |
|
971.1.46
by Monty Taylor
Made plugin registration go through Plugin_registry. |
30 |
#include "drizzled/show.h" |
1183.1.2
by Brian Aker
Rename of handler to Cursor. You would not believe how long I have wanted |
31 |
#include "drizzled/cursor.h" |
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
32 |
|
1966.2.6
by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing |
33 |
#include <boost/bind.hpp> |
34 |
||
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
35 |
using namespace std; |
36 |
||
1130.1.1
by Monty Taylor
Merged in plugin-slot-reorg patches. |
37 |
namespace drizzled |
38 |
{
|
|
1110.1.5
by Monty Taylor
Renamed PluginRegistry to plugin::Registry. |
39 |
|
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
40 |
|
41 |
module::Registry::~Registry() |
|
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
42 |
{
|
1966.2.6
by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing |
43 |
std::map<std::string, plugin::Plugin *>::iterator plugin_iter; |
1784.4.1
by Paul McCullagh
Fixed PBXT recovery and shutdown, added shutdownPlugin() call to all plugins before the plugins are deleted |
44 |
|
45 |
/* Give all plugins a chance to cleanup, before
|
|
46 |
* all plugins are deleted.
|
|
47 |
* This can be used if shutdown code references
|
|
48 |
* other plugins.
|
|
49 |
*/
|
|
50 |
plugin_iter= plugin_registry.begin(); |
|
51 |
while (plugin_iter != plugin_registry.end()) |
|
52 |
{
|
|
53 |
(*plugin_iter).second->shutdownPlugin(); |
|
54 |
++plugin_iter; |
|
55 |
}
|
|
56 |
||
57 |
plugin_iter= plugin_registry.begin(); |
|
1324.2.3
by Monty Taylor
Remove plugin deinit. |
58 |
while (plugin_iter != plugin_registry.end()) |
59 |
{
|
|
60 |
delete (*plugin_iter).second; |
|
61 |
++plugin_iter; |
|
62 |
}
|
|
63 |
plugin_registry.clear(); |
|
64 |
||
1966.2.6
by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing |
65 |
#if 0
|
66 |
@TODO When we delete modules here, we segfault on a bad string. Why?
|
|
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
67 |
map<string, module::Module *>::iterator module_iter= module_map.begin();
|
1966.2.6
by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing |
68 |
|
1324.2.3
by Monty Taylor
Remove plugin deinit. |
69 |
while (module_iter != module_map.end())
|
70 |
{
|
|
71 |
delete (*module_iter).second;
|
|
72 |
++module_iter;
|
|
73 |
}
|
|
74 |
module_map.clear();
|
|
1966.2.6
by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing |
75 |
#endif
|
76 |
std::map<std::string, module::Library *>::iterator library_iter= library_map.begin(); |
|
1324.2.3
by Monty Taylor
Remove plugin deinit. |
77 |
while (library_iter != library_map.end()) |
78 |
{
|
|
79 |
delete (*library_iter).second; |
|
80 |
++library_iter; |
|
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
81 |
}
|
82 |
library_map.clear(); |
|
83 |
}
|
|
84 |
||
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
85 |
void module::Registry::shutdown() |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
86 |
{
|
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
87 |
module::Registry& registry= singleton(); |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
88 |
delete ®istry; |
89 |
}
|
|
90 |
||
1966.2.6
by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing |
91 |
module::Module *module::Registry::find(std::string name) |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
92 |
{
|
1966.2.6
by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing |
93 |
std::transform(name.begin(), name.end(), name.begin(), ::tolower); |
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
94 |
|
1966.2.6
by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing |
95 |
std::map<std::string, module::Module *>::iterator map_iter; |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
96 |
map_iter= module_map.find(name); |
1192.2.3
by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity. |
97 |
if (map_iter != module_map.end()) |
971.1.54
by Monty Taylor
Trimmed out some plugin type stuff. |
98 |
return (*map_iter).second; |
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
99 |
return(0); |
100 |
}
|
|
101 |
||
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
102 |
void module::Registry::add(module::Module *handle) |
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
103 |
{
|
1966.2.6
by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing |
104 |
std::string add_str(handle->getName()); |
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
105 |
transform(add_str.begin(), add_str.end(), |
106 |
add_str.begin(), ::tolower); |
|
107 |
||
1192.2.3
by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity. |
108 |
module_map[add_str]= handle; |
1130.2.2
by Monty Taylor
Added support for the global list of plugin::Plugin objects to slot::Function |
109 |
}
|
110 |
||
1702.4.1
by LinuxJedi
Remove module pointer from registry when module doesn't load to avoid a double-free on shutdown. |
111 |
void module::Registry::remove(module::Module *handle) |
112 |
{
|
|
1966.2.6
by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing |
113 |
std::string remove_str(handle->getName()); |
114 |
std::transform(remove_str.begin(), remove_str.end(), |
|
115 |
remove_str.begin(), ::tolower); |
|
1702.4.1
by LinuxJedi
Remove module pointer from registry when module doesn't load to avoid a double-free on shutdown. |
116 |
|
117 |
module_map.erase(remove_str); |
|
118 |
}
|
|
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
119 |
|
1966.2.6
by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing |
120 |
void module::Registry::copy(plugin::Plugin::vector &arg) |
121 |
{
|
|
122 |
arg.reserve(plugin_registry.size()); |
|
123 |
||
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()); |
|
129 |
}
|
|
130 |
||
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
131 |
vector<module::Module *> module::Registry::getList(bool active) |
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
132 |
{
|
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
133 |
module::Module *plugin= NULL; |
1192.2.3
by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity. |
134 |
|
1966.2.6
by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing |
135 |
std::vector<module::Module *> plugins; |
1192.2.3
by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity. |
136 |
plugins.reserve(module_map.size()); |
137 |
||
1966.2.6
by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing |
138 |
std::map<std::string, module::Module *>::iterator map_iter; |
1192.2.3
by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity. |
139 |
for (map_iter= module_map.begin(); |
140 |
map_iter != module_map.end(); |
|
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
141 |
map_iter++) |
142 |
{
|
|
143 |
plugin= (*map_iter).second; |
|
965.1.1
by Brian Aker
Refactor plugin loading to remove mask (one step closer to getting rid of |
144 |
if (active) |
145 |
plugins.push_back(plugin); |
|
146 |
else if (plugin->isInited) |
|
147 |
plugins.push_back(plugin); |
|
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
148 |
}
|
971.1.54
by Monty Taylor
Trimmed out some plugin type stuff. |
149 |
|
150 |
return plugins; |
|
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
151 |
}
|
971.1.46
by Monty Taylor
Made plugin registration go through Plugin_registry. |
152 |
|
1966.2.6
by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing |
153 |
module::Library *module::Registry::addLibrary(const std::string &plugin_name, |
1530.2.3
by Monty Taylor
Changed the builtin plugin code path to work exactly the same as dynamic. |
154 |
bool builtin) |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
155 |
{
|
156 |
||
157 |
/* If this dll is already loaded just return it */
|
|
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
158 |
module::Library *library= findLibrary(plugin_name); |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
159 |
if (library != NULL) |
160 |
{
|
|
161 |
return library; |
|
162 |
}
|
|
163 |
||
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
164 |
library= module::Library::loadLibrary(plugin_name, builtin); |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
165 |
if (library != NULL) |
166 |
{
|
|
167 |
/* Add this dll to the map */
|
|
168 |
library_map.insert(make_pair(plugin_name, library)); |
|
169 |
}
|
|
170 |
||
171 |
return library; |
|
172 |
}
|
|
173 |
||
1966.2.6
by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing |
174 |
void module::Registry::removeLibrary(const std::string &plugin_name) |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
175 |
{
|
1966.2.6
by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing |
176 |
std::map<std::string, module::Library *>::iterator iter= |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
177 |
library_map.find(plugin_name); |
178 |
if (iter != library_map.end()) |
|
179 |
{
|
|
180 |
library_map.erase(iter); |
|
181 |
delete (*iter).second; |
|
182 |
}
|
|
183 |
}
|
|
184 |
||
1966.2.6
by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing |
185 |
module::Library *module::Registry::findLibrary(const std::string &plugin_name) const |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
186 |
{
|
1966.2.6
by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing |
187 |
std::map<std::string, module::Library *>::const_iterator iter= |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
188 |
library_map.find(plugin_name); |
189 |
if (iter != library_map.end()) |
|
190 |
return (*iter).second; |
|
191 |
return NULL; |
|
192 |
}
|
|
193 |
||
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
194 |
void module::Registry::shutdownModules() |
195 |
{
|
|
196 |
module_shutdown(*this); |
|
197 |
}
|
|
198 |
||
1130.1.1
by Monty Taylor
Merged in plugin-slot-reorg patches. |
199 |
} /* namespace drizzled */ |