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 |
||
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
20 |
#ifndef DRIZZLED_MODULE_REGISTRY_H
|
21 |
#define DRIZZLED_MODULE_REGISTRY_H
|
|
971.1.45
by Monty Taylor
Collapsed plugin_registry. _impl class not needed. |
22 |
|
1130.1.2
by Monty Taylor
Re-org'd the replication stuff into slots. |
23 |
#include <string> |
24 |
#include <vector> |
|
25 |
#include <map> |
|
1192.2.8
by Monty Taylor
Updated plugin::Registry to use std::map instead of NameMap. |
26 |
#include <algorithm> |
2139.3.11
by Brian Aker
Error log messages from Inno, most, not all are sent to the correct error |
27 |
#include <iostream> |
1130.1.2
by Monty Taylor
Re-org'd the replication stuff into slots. |
28 |
|
2095.3.7
by Monty Taylor
Fixed the dependency graph so that it doesn't get included in sql_yacc.yy. |
29 |
#include <boost/scoped_ptr.hpp> |
30 |
||
1130.1.19
by Monty Taylor
Added error reporting to plugin registration. |
31 |
#include "drizzled/gettext.h" |
32 |
#include "drizzled/unireg.h" |
|
1192.2.8
by Monty Taylor
Updated plugin::Registry to use std::map instead of NameMap. |
33 |
#include "drizzled/errmsg_print.h" |
1966.2.6
by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing |
34 |
#include "drizzled/plugin/plugin.h" |
2095.3.4
by Monty Taylor
Split out module vertex and then actually used it. |
35 |
|
2095.3.2
by Monty Taylor
Add the depend graph to module::Registry. |
36 |
|
971.1.49
by Monty Taylor
Hooked transaction_services into Plugin_registry. |
37 |
namespace drizzled |
38 |
{
|
|
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
39 |
|
40 |
namespace module |
|
41 |
{
|
|
1192.2.3
by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity. |
42 |
class Module; |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
43 |
class Library; |
2095.3.7
by Monty Taylor
Fixed the dependency graph so that it doesn't get included in sql_yacc.yy. |
44 |
class Graph; |
971.1.46
by Monty Taylor
Made plugin registration go through Plugin_registry. |
45 |
|
2095.3.2
by Monty Taylor
Add the depend graph to module::Registry. |
46 |
|
1110.1.5
by Monty Taylor
Renamed PluginRegistry to plugin::Registry. |
47 |
class Registry |
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
48 |
{
|
2068.2.1
by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name |
49 |
public: |
2095.3.2
by Monty Taylor
Add the depend graph to module::Registry. |
50 |
|
2068.2.1
by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name |
51 |
typedef std::map<std::string, Library *> LibraryMap; |
52 |
typedef std::map<std::string, Module *> ModuleMap; |
|
2095.3.5
by Monty Taylor
Use the catalog registry. |
53 |
typedef std::vector<Module *> ModuleList; |
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
54 |
private: |
2068.2.1
by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name |
55 |
LibraryMap library_registry_; |
56 |
ModuleMap module_registry_; |
|
2095.3.7
by Monty Taylor
Fixed the dependency graph so that it doesn't get included in sql_yacc.yy. |
57 |
boost::scoped_ptr<Graph> depend_graph_; |
2068.2.1
by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name |
58 |
|
59 |
plugin::Plugin::map plugin_registry; |
|
1130.2.2
by Monty Taylor
Added support for the global list of plugin::Plugin objects to slot::Function |
60 |
|
2095.3.6
by Monty Taylor
Actually properly process module dependencies. w00t. |
61 |
bool deps_built_; |
62 |
||
2095.3.7
by Monty Taylor
Fixed the dependency graph so that it doesn't get included in sql_yacc.yy. |
63 |
Registry(); |
1110.1.5
by Monty Taylor
Renamed PluginRegistry to plugin::Registry. |
64 |
Registry(const Registry&); |
1130.2.16
by Monty Taylor
Cleaned up the constructor initializer lists per Brian. |
65 |
Registry& operator=(const Registry&); |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
66 |
~Registry(); |
2095.3.2
by Monty Taylor
Add the depend graph to module::Registry. |
67 |
|
2095.3.6
by Monty Taylor
Actually properly process module dependencies. w00t. |
68 |
void buildDeps(); |
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
69 |
public: |
70 |
||
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
71 |
static Registry& singleton() |
1110.1.3
by Monty Taylor
Added ListenHandler as a member of PluginRegistry. |
72 |
{
|
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
73 |
static Registry *registry= new Registry(); |
971.7.1
by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup. |
74 |
return *registry; |
75 |
}
|
|
76 |
||
1966.2.6
by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing |
77 |
void copy(plugin::Plugin::vector &arg); |
78 |
||
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
79 |
static void shutdown(); |
1110.1.3
by Monty Taylor
Added ListenHandler as a member of PluginRegistry. |
80 |
|
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
81 |
Module *find(std::string name); |
1192.2.3
by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity. |
82 |
|
83 |
void add(Module *module); |
|
84 |
||
1702.4.1
by LinuxJedi
Remove module pointer from registry when module doesn't load to avoid a double-free on shutdown. |
85 |
void remove(Module *module); |
1192.2.3
by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity. |
86 |
|
2095.3.5
by Monty Taylor
Use the catalog registry. |
87 |
std::vector<Module *> getList(); |
971.1.52
by Monty Taylor
Did the finalizers. Renamed plugin_registry. |
88 |
|
2068.2.1
by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name |
89 |
const plugin::Plugin::map &getPluginsMap() const |
1192.2.8
by Monty Taylor
Updated plugin::Registry to use std::map instead of NameMap. |
90 |
{
|
91 |
return plugin_registry; |
|
1192.2.1
by Monty Taylor
Added the MODULES table. |
92 |
}
|
93 |
||
2068.2.1
by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name |
94 |
const ModuleMap &getModulesMap() const |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
95 |
{
|
2068.2.1
by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name |
96 |
return module_registry_; |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
97 |
}
|
98 |
||
1530.2.3
by Monty Taylor
Changed the builtin plugin code path to work exactly the same as dynamic. |
99 |
Library *addLibrary(const std::string &plugin_name, bool builtin= false); |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
100 |
void removeLibrary(const std::string &plugin_name); |
101 |
Library *findLibrary(const std::string &plugin_name) const; |
|
102 |
||
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
103 |
void shutdownModules(); |
104 |
||
1130.1.12
by Monty Taylor
Moved service stuff into plugin/ |
105 |
template<class T> |
106 |
void add(T *plugin) |
|
107 |
{
|
|
1130.2.8
by Monty Taylor
Merged latest changes from plugin-slot-reorg. |
108 |
bool failed= false; |
2068.2.1
by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name |
109 |
std::string plugin_type(plugin->getTypeName()); |
110 |
std::transform(plugin_type.begin(), plugin_type.end(), |
|
111 |
plugin_type.begin(), ::tolower); |
|
1192.2.8
by Monty Taylor
Updated plugin::Registry to use std::map instead of NameMap. |
112 |
std::string plugin_name(plugin->getName()); |
113 |
std::transform(plugin_name.begin(), plugin_name.end(), |
|
114 |
plugin_name.begin(), ::tolower); |
|
2068.2.1
by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name |
115 |
if (plugin_registry.find(std::make_pair(plugin_type, plugin_name)) != plugin_registry.end()) |
1192.2.8
by Monty Taylor
Updated plugin::Registry to use std::map instead of NameMap. |
116 |
{
|
2126.3.3
by Brian Aker
Merge in error message rework. Many error messages are fixed in this patch. |
117 |
errmsg_printf(error::ERROR, |
2068.2.1
by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name |
118 |
_("Loading plugin %s failed: a %s plugin by that name " |
119 |
"already exists.\n"), |
|
120 |
plugin->getTypeName().c_str(), |
|
121 |
plugin->getName().c_str()); |
|
1130.2.8
by Monty Taylor
Merged latest changes from plugin-slot-reorg. |
122 |
failed= true; |
1192.2.8
by Monty Taylor
Updated plugin::Registry to use std::map instead of NameMap. |
123 |
}
|
1130.2.8
by Monty Taylor
Merged latest changes from plugin-slot-reorg. |
124 |
if (T::addPlugin(plugin)) |
2068.2.1
by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name |
125 |
{
|
1130.2.8
by Monty Taylor
Merged latest changes from plugin-slot-reorg. |
126 |
failed= true; |
2068.2.1
by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name |
127 |
}
|
128 |
||
1130.1.19
by Monty Taylor
Added error reporting to plugin registration. |
129 |
if (failed) |
130 |
{
|
|
2126.3.3
by Brian Aker
Merge in error message rework. Many error messages are fixed in this patch. |
131 |
errmsg_printf(error::ERROR, |
2068.2.1
by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name |
132 |
_("Fatal error: Failed initializing %s::%s plugin.\n"), |
133 |
plugin->getTypeName().c_str(), |
|
1192.2.8
by Monty Taylor
Updated plugin::Registry to use std::map instead of NameMap. |
134 |
plugin->getName().c_str()); |
1130.1.19
by Monty Taylor
Added error reporting to plugin registration. |
135 |
unireg_abort(1); |
136 |
}
|
|
2068.2.1
by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name |
137 |
plugin_registry.insert(std::make_pair(std::make_pair(plugin_type, plugin_name), plugin)); |
1130.1.12
by Monty Taylor
Moved service stuff into plugin/ |
138 |
}
|
139 |
||
140 |
template<class T> |
|
141 |
void remove(T *plugin) |
|
142 |
{
|
|
2068.2.1
by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name |
143 |
std::string plugin_type(plugin->getTypeName()); |
144 |
std::transform(plugin_type.begin(), plugin_type.end(), |
|
145 |
plugin_type.begin(), ::tolower); |
|
1192.2.8
by Monty Taylor
Updated plugin::Registry to use std::map instead of NameMap. |
146 |
std::string plugin_name(plugin->getName()); |
147 |
std::transform(plugin_name.begin(), plugin_name.end(), |
|
148 |
plugin_name.begin(), ::tolower); |
|
1130.1.18
by Monty Taylor
Changed ::add() and ::remove() to ::addPlugin() and ::removePlugin() so that |
149 |
T::removePlugin(plugin); |
2068.2.1
by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name |
150 |
plugin_registry.erase(std::make_pair(plugin_type, plugin_name)); |
1130.1.12
by Monty Taylor
Moved service stuff into plugin/ |
151 |
}
|
1130.1.8
by Monty Taylor
Added polymorphic add/remove methods around slot add/remove methods. |
152 |
|
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
153 |
|
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
154 |
};
|
971.1.45
by Monty Taylor
Collapsed plugin_registry. _impl class not needed. |
155 |
|
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
156 |
} /* namespace module */ |
157 |
} /* namespace drizzled */ |
|
158 |
#endif /* DRIZZLED_MODULE_REGISTRY_H */ |