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 |
||
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
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 |
||
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
26 |
#include <drizzled/module/registry.h> |
27 |
#include <drizzled/module/library.h> |
|
28 |
#include <drizzled/module/graph.h> |
|
29 |
#include <drizzled/module/vertex_handle.h> |
|
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
30 |
|
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
31 |
#include <drizzled/plugin.h> |
32 |
#include <drizzled/show.h> |
|
33 |
#include <drizzled/cursor.h> |
|
34 |
#include <drizzled/abort_exception.h> |
|
2282.1.3
by Olaf van der Spek
Refactor Module Registry |
35 |
#include <drizzled/util/find_ptr.h> |
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
36 |
|
1966.2.6
by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing |
37 |
#include <boost/bind.hpp> |
2282.1.3
by Olaf van der Spek
Refactor Module Registry |
38 |
#include <boost/foreach.hpp> |
1966.2.6
by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing |
39 |
|
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
40 |
using namespace std; |
41 |
||
2282.1.3
by Olaf van der Spek
Refactor Module Registry |
42 |
namespace drizzled { |
1110.1.5
by Monty Taylor
Renamed PluginRegistry to plugin::Registry. |
43 |
|
2095.3.7
by Monty Taylor
Fixed the dependency graph so that it doesn't get included in sql_yacc.yy. |
44 |
module::Registry::Registry() : |
45 |
module_registry_(), |
|
46 |
depend_graph_(new module::Graph()), |
|
47 |
plugin_registry(), |
|
48 |
deps_built_(false) |
|
49 |
{ } |
|
50 |
||
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
51 |
|
52 |
module::Registry::~Registry() |
|
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
53 |
{
|
1784.4.1
by Paul McCullagh
Fixed PBXT recovery and shutdown, added shutdownPlugin() call to all plugins before the plugins are deleted |
54 |
/* Give all plugins a chance to cleanup, before
|
55 |
* all plugins are deleted.
|
|
56 |
* This can be used if shutdown code references
|
|
57 |
* other plugins.
|
|
58 |
*/
|
|
2282.1.3
by Olaf van der Spek
Refactor Module Registry |
59 |
BOOST_FOREACH(plugin::Plugin::map::reference it, plugin_registry) |
60 |
it.second->shutdownPlugin(); |
|
1784.4.1
by Paul McCullagh
Fixed PBXT recovery and shutdown, added shutdownPlugin() call to all plugins before the plugins are deleted |
61 |
|
2139.3.11
by Brian Aker
Error log messages from Inno, most, not all are sent to the correct error |
62 |
plugin::Plugin::vector error_plugins; |
2282.1.3
by Olaf van der Spek
Refactor Module Registry |
63 |
BOOST_FOREACH(plugin::Plugin::map::reference it, plugin_registry) |
1324.2.3
by Monty Taylor
Remove plugin deinit. |
64 |
{
|
2282.1.3
by Olaf van der Spek
Refactor Module Registry |
65 |
if (it.second->removeLast()) |
66 |
error_plugins.push_back(it.second); |
|
2139.3.11
by Brian Aker
Error log messages from Inno, most, not all are sent to the correct error |
67 |
else
|
2282.1.3
by Olaf van der Spek
Refactor Module Registry |
68 |
delete it.second; |
1324.2.3
by Monty Taylor
Remove plugin deinit. |
69 |
}
|
2139.3.11
by Brian Aker
Error log messages from Inno, most, not all are sent to the correct error |
70 |
|
2282.1.3
by Olaf van der Spek
Refactor Module Registry |
71 |
BOOST_FOREACH(plugin::Plugin::vector::reference it, error_plugins) |
72 |
delete it; |
|
2139.3.11
by Brian Aker
Error log messages from Inno, most, not all are sent to the correct error |
73 |
|
1324.2.3
by Monty Taylor
Remove plugin deinit. |
74 |
plugin_registry.clear(); |
75 |
||
1966.2.6
by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing |
76 |
#if 0
|
2282.1.4
by Olaf van der Spek
Refactor |
77 |
/*
|
1966.2.6
by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing |
78 |
@TODO When we delete modules here, we segfault on a bad string. Why?
|
2282.1.4
by Olaf van der Spek
Refactor |
79 |
*/
|
1966.2.6
by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing |
80 |
|
2282.1.4
by Olaf van der Spek
Refactor |
81 |
BOOST_FOREACH(ModuleMap::reference it, module_registry_)
|
82 |
delete it.second;
|
|
2068.2.1
by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name |
83 |
module_registry_.clear();
|
1966.2.6
by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing |
84 |
#endif
|
2282.1.3
by Olaf van der Spek
Refactor Module Registry |
85 |
BOOST_FOREACH(LibraryMap::reference it, library_registry_) |
86 |
delete it.second; |
|
2068.2.1
by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name |
87 |
library_registry_.clear(); |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
88 |
}
|
89 |
||
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
90 |
void module::Registry::shutdown() |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
91 |
{
|
2282.1.3
by Olaf van der Spek
Refactor Module Registry |
92 |
delete &singleton(); |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
93 |
}
|
94 |
||
2282.1.5
by Olaf van der Spek
Refactor Module Registry |
95 |
module::Module* module::Registry::find(const std::string& name) |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
96 |
{
|
2282.1.3
by Olaf van der Spek
Refactor Module Registry |
97 |
return find_ptr2(module_registry_, boost::to_lower_copy(name)); |
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
98 |
}
|
99 |
||
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
100 |
void module::Registry::add(module::Module *handle) |
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
101 |
{
|
2282.1.3
by Olaf van der Spek
Refactor Module Registry |
102 |
std::string add_str(boost::to_lower_copy(handle->getName())); |
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
103 |
|
2068.2.1
by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name |
104 |
module_registry_[add_str]= handle; |
2095.3.3
by Monty Taylor
Insert module into the vertex list. |
105 |
|
2095.3.4
by Monty Taylor
Split out module vertex and then actually used it. |
106 |
Vertex vertex_info(add_str, handle); |
2095.3.7
by Monty Taylor
Fixed the dependency graph so that it doesn't get included in sql_yacc.yy. |
107 |
VertexDesc handle_vertex= boost::add_vertex(depend_graph_->getGraph()); |
108 |
depend_graph_->properties(handle_vertex)= vertex_info; |
|
2095.3.5
by Monty Taylor
Use the catalog registry. |
109 |
|
2095.3.7
by Monty Taylor
Fixed the dependency graph so that it doesn't get included in sql_yacc.yy. |
110 |
handle->setVertexHandle(new VertexHandle(handle_vertex)); |
1130.2.2
by Monty Taylor
Added support for the global list of plugin::Plugin objects to slot::Function |
111 |
}
|
112 |
||
1702.4.1
by LinuxJedi
Remove module pointer from registry when module doesn't load to avoid a double-free on shutdown. |
113 |
void module::Registry::remove(module::Module *handle) |
114 |
{
|
|
2282.1.3
by Olaf van der Spek
Refactor Module Registry |
115 |
module_registry_.erase(boost::to_lower_copy(handle->getName())); |
1702.4.1
by LinuxJedi
Remove module pointer from registry when module doesn't load to avoid a double-free on shutdown. |
116 |
}
|
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
117 |
|
2095.3.6
by Monty Taylor
Actually properly process module dependencies. w00t. |
118 |
void module::Registry::buildDeps() |
119 |
{
|
|
2282.1.3
by Olaf van der Spek
Refactor Module Registry |
120 |
BOOST_FOREACH(ModuleMap::reference map_iter, module_registry_) |
2095.3.6
by Monty Taylor
Actually properly process module dependencies. w00t. |
121 |
{
|
2282.1.3
by Olaf van der Spek
Refactor Module Registry |
122 |
Module* handle= map_iter.second; |
123 |
BOOST_FOREACH(Module::Depends::const_reference handle_deps, handle->getDepends()) |
|
2095.3.6
by Monty Taylor
Actually properly process module dependencies. w00t. |
124 |
{
|
2282.1.3
by Olaf van der Spek
Refactor Module Registry |
125 |
std::string dep_str(boost::to_lower_copy(handle_deps)); |
2095.3.6
by Monty Taylor
Actually properly process module dependencies. w00t. |
126 |
bool found_dep= false; |
2282.1.3
by Olaf van der Spek
Refactor Module Registry |
127 |
for (vertex_iter it= boost::vertices(depend_graph_->getGraph()).first; it != vertices(depend_graph_->getGraph()).second; it++) |
2095.3.6
by Monty Taylor
Actually properly process module dependencies. w00t. |
128 |
{
|
2095.3.7
by Monty Taylor
Fixed the dependency graph so that it doesn't get included in sql_yacc.yy. |
129 |
if (depend_graph_->properties(*it).getName() == dep_str) |
2095.3.6
by Monty Taylor
Actually properly process module dependencies. w00t. |
130 |
{
|
131 |
found_dep= true; |
|
2095.3.7
by Monty Taylor
Fixed the dependency graph so that it doesn't get included in sql_yacc.yy. |
132 |
add_edge(handle->getVertexHandle()->getVertexDesc(), *it, depend_graph_->getGraph()); |
2095.3.6
by Monty Taylor
Actually properly process module dependencies. w00t. |
133 |
break; |
134 |
}
|
|
135 |
}
|
|
136 |
if (not found_dep) |
|
137 |
{
|
|
2318.6.57
by Olaf van der Spek
Refactor |
138 |
errmsg_printf(error::ERROR, _("Couldn't process plugin module dependencies. %s depends on %s but %s is not to be loaded.\n"), |
139 |
handle->getName().c_str(), dep_str.c_str(), dep_str.c_str()); |
|
2095.3.6
by Monty Taylor
Actually properly process module dependencies. w00t. |
140 |
DRIZZLE_ABORT; |
141 |
}
|
|
142 |
}
|
|
143 |
}
|
|
144 |
deps_built_= true; |
|
145 |
}
|
|
146 |
||
2095.3.5
by Monty Taylor
Use the catalog registry. |
147 |
module::Registry::ModuleList module::Registry::getList() |
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
148 |
{
|
2095.3.6
by Monty Taylor
Actually properly process module dependencies. w00t. |
149 |
if (not deps_built_) |
150 |
buildDeps(); |
|
2095.3.5
by Monty Taylor
Use the catalog registry. |
151 |
VertexList vertex_list; |
2095.3.7
by Monty Taylor
Fixed the dependency graph so that it doesn't get included in sql_yacc.yy. |
152 |
boost::topological_sort(depend_graph_->getGraph(), std::back_inserter(vertex_list)); |
2282.1.3
by Olaf van der Spek
Refactor Module Registry |
153 |
ModuleList plugins; |
154 |
BOOST_FOREACH(VertexList::reference it, vertex_list) |
|
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
155 |
{
|
2282.1.3
by Olaf van der Spek
Refactor Module Registry |
156 |
if (Module* mod_ptr= depend_graph_->properties(it).getModule()) |
2095.3.6
by Monty Taylor
Actually properly process module dependencies. w00t. |
157 |
plugins.push_back(mod_ptr); |
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
158 |
}
|
971.1.54
by Monty Taylor
Trimmed out some plugin type stuff. |
159 |
return plugins; |
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
160 |
}
|
971.1.46
by Monty Taylor
Made plugin registration go through Plugin_registry. |
161 |
|
2318.6.57
by Olaf van der Spek
Refactor |
162 |
module::Library *module::Registry::addLibrary(const std::string &plugin_name, bool builtin) |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
163 |
{
|
164 |
/* 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 |
165 |
module::Library *library= findLibrary(plugin_name); |
2282.1.3
by Olaf van der Spek
Refactor Module Registry |
166 |
if (library) |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
167 |
return library; |
168 |
||
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
169 |
library= module::Library::loadLibrary(plugin_name, builtin); |
2282.1.3
by Olaf van der Spek
Refactor Module Registry |
170 |
if (library) |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
171 |
{
|
172 |
/* Add this dll to the map */
|
|
2068.2.1
by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name |
173 |
library_registry_.insert(make_pair(plugin_name, library)); |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
174 |
}
|
175 |
return library; |
|
176 |
}
|
|
177 |
||
1966.2.6
by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing |
178 |
void module::Registry::removeLibrary(const std::string &plugin_name) |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
179 |
{
|
2282.1.3
by Olaf van der Spek
Refactor Module Registry |
180 |
LibraryMap::iterator iter= library_registry_.find(plugin_name); |
2068.2.1
by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name |
181 |
if (iter != library_registry_.end()) |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
182 |
{
|
2318.6.57
by Olaf van der Spek
Refactor |
183 |
delete iter->second; |
2068.2.1
by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name |
184 |
library_registry_.erase(iter); |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
185 |
}
|
186 |
}
|
|
187 |
||
1966.2.6
by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing |
188 |
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: |
189 |
{
|
2282.1.3
by Olaf van der Spek
Refactor Module Registry |
190 |
return find_ptr2(library_registry_, plugin_name); |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
191 |
}
|
192 |
||
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
193 |
void module::Registry::shutdownModules() |
194 |
{
|
|
195 |
module_shutdown(*this); |
|
196 |
}
|
|
197 |
||
1130.1.1
by Monty Taylor
Merged in plugin-slot-reorg patches. |
198 |
} /* namespace drizzled */ |