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 |
*
|
|
4 |
* Copyright (C) 2008 Sun Microsystems
|
|
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> |
1130.1.2
by Monty Taylor
Re-org'd the replication stuff into slots. |
27 |
|
1130.1.19
by Monty Taylor
Added error reporting to plugin registration. |
28 |
#include "drizzled/gettext.h" |
29 |
#include "drizzled/unireg.h" |
|
1192.2.8
by Monty Taylor
Updated plugin::Registry to use std::map instead of NameMap. |
30 |
#include "drizzled/errmsg_print.h" |
1110.1.5
by Monty Taylor
Renamed PluginRegistry to plugin::Registry. |
31 |
|
971.1.49
by Monty Taylor
Hooked transaction_services into Plugin_registry. |
32 |
namespace drizzled |
33 |
{
|
|
34 |
namespace plugin |
|
35 |
{
|
|
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
36 |
class Plugin; |
37 |
}
|
|
38 |
||
39 |
namespace module |
|
40 |
{
|
|
1192.2.3
by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity. |
41 |
class Module; |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
42 |
class Library; |
971.1.46
by Monty Taylor
Made plugin registration go through Plugin_registry. |
43 |
|
1110.1.5
by Monty Taylor
Renamed PluginRegistry to plugin::Registry. |
44 |
class Registry |
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
45 |
{
|
46 |
private: |
|
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
47 |
std::map<std::string, Library *> library_map; |
1192.2.3
by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity. |
48 |
std::map<std::string, Module *> module_map; |
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
49 |
std::map<std::string, plugin::Plugin *> plugin_registry; |
1130.2.2
by Monty Taylor
Added support for the global list of plugin::Plugin objects to slot::Function |
50 |
|
51 |
Registry() |
|
1192.2.3
by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity. |
52 |
: module_map(), |
1324.2.1
by Monty Taylor
Create a plugin::Context object to carry information about the plugin module |
53 |
plugin_registry() |
1130.2.2
by Monty Taylor
Added support for the global list of plugin::Plugin objects to slot::Function |
54 |
{ } |
55 |
||
1110.1.5
by Monty Taylor
Renamed PluginRegistry to plugin::Registry. |
56 |
Registry(const Registry&); |
1130.2.16
by Monty Taylor
Cleaned up the constructor initializer lists per Brian. |
57 |
Registry& operator=(const Registry&); |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
58 |
~Registry(); |
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
59 |
public: |
60 |
||
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
61 |
static Registry& singleton() |
1110.1.3
by Monty Taylor
Added ListenHandler as a member of PluginRegistry. |
62 |
{
|
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
63 |
static Registry *registry= new Registry(); |
971.7.1
by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup. |
64 |
return *registry; |
65 |
}
|
|
66 |
||
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
67 |
static void shutdown(); |
1110.1.3
by Monty Taylor
Added ListenHandler as a member of PluginRegistry. |
68 |
|
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
69 |
Module *find(std::string name); |
1192.2.3
by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity. |
70 |
|
71 |
void add(Module *module); |
|
72 |
||
1702.4.1
by LinuxJedi
Remove module pointer from registry when module doesn't load to avoid a double-free on shutdown. |
73 |
void remove(Module *module); |
1192.2.3
by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity. |
74 |
|
75 |
std::vector<Module *> getList(bool active); |
|
971.1.52
by Monty Taylor
Did the finalizers. Renamed plugin_registry. |
76 |
|
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
77 |
const std::map<std::string, plugin::Plugin *> &getPluginsMap() const |
1192.2.8
by Monty Taylor
Updated plugin::Registry to use std::map instead of NameMap. |
78 |
{
|
79 |
return plugin_registry; |
|
1192.2.1
by Monty Taylor
Added the MODULES table. |
80 |
}
|
81 |
||
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
82 |
const std::map<std::string, Module *> &getModulesMap() const |
83 |
{
|
|
84 |
return module_map; |
|
85 |
}
|
|
86 |
||
1530.2.3
by Monty Taylor
Changed the builtin plugin code path to work exactly the same as dynamic. |
87 |
Library *addLibrary(const std::string &plugin_name, bool builtin= false); |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
88 |
void removeLibrary(const std::string &plugin_name); |
89 |
Library *findLibrary(const std::string &plugin_name) const; |
|
90 |
||
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
91 |
void shutdownModules(); |
92 |
||
1130.1.12
by Monty Taylor
Moved service stuff into plugin/ |
93 |
template<class T> |
94 |
void add(T *plugin) |
|
95 |
{
|
|
1130.2.8
by Monty Taylor
Merged latest changes from plugin-slot-reorg. |
96 |
bool failed= false; |
1192.2.8
by Monty Taylor
Updated plugin::Registry to use std::map instead of NameMap. |
97 |
std::string plugin_name(plugin->getName()); |
98 |
std::transform(plugin_name.begin(), plugin_name.end(), |
|
99 |
plugin_name.begin(), ::tolower); |
|
100 |
if (plugin_registry.find(plugin_name) != plugin_registry.end()) |
|
101 |
{
|
|
102 |
errmsg_printf(ERRMSG_LVL_ERROR, |
|
103 |
_("Loading plugin %s failed: a plugin by that name already " |
|
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
104 |
"exists.\n"), plugin->getName().c_str()); |
1130.2.8
by Monty Taylor
Merged latest changes from plugin-slot-reorg. |
105 |
failed= true; |
1192.2.8
by Monty Taylor
Updated plugin::Registry to use std::map instead of NameMap. |
106 |
}
|
1130.2.8
by Monty Taylor
Merged latest changes from plugin-slot-reorg. |
107 |
if (T::addPlugin(plugin)) |
108 |
failed= true; |
|
1130.1.19
by Monty Taylor
Added error reporting to plugin registration. |
109 |
if (failed) |
110 |
{
|
|
1192.2.8
by Monty Taylor
Updated plugin::Registry to use std::map instead of NameMap. |
111 |
errmsg_printf(ERRMSG_LVL_ERROR, |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
112 |
_("Fatal error: Failed initializing %s plugin.\n"), |
1192.2.8
by Monty Taylor
Updated plugin::Registry to use std::map instead of NameMap. |
113 |
plugin->getName().c_str()); |
1130.1.19
by Monty Taylor
Added error reporting to plugin registration. |
114 |
unireg_abort(1); |
115 |
}
|
|
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
116 |
plugin_registry.insert(std::pair<std::string, plugin::Plugin *>(plugin_name, plugin)); |
1130.1.12
by Monty Taylor
Moved service stuff into plugin/ |
117 |
}
|
118 |
||
119 |
template<class T> |
|
120 |
void remove(T *plugin) |
|
121 |
{
|
|
1192.2.8
by Monty Taylor
Updated plugin::Registry to use std::map instead of NameMap. |
122 |
std::string plugin_name(plugin->getName()); |
123 |
std::transform(plugin_name.begin(), plugin_name.end(), |
|
124 |
plugin_name.begin(), ::tolower); |
|
1130.1.18
by Monty Taylor
Changed ::add() and ::remove() to ::addPlugin() and ::removePlugin() so that |
125 |
T::removePlugin(plugin); |
1192.2.8
by Monty Taylor
Updated plugin::Registry to use std::map instead of NameMap. |
126 |
plugin_registry.erase(plugin_name); |
1130.1.12
by Monty Taylor
Moved service stuff into plugin/ |
127 |
}
|
1130.1.8
by Monty Taylor
Added polymorphic add/remove methods around slot add/remove methods. |
128 |
|
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
129 |
|
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
130 |
};
|
971.1.45
by Monty Taylor
Collapsed plugin_registry. _impl class not needed. |
131 |
|
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
132 |
} /* namespace module */ |
133 |
} /* namespace drizzled */ |
|
134 |
#endif /* DRIZZLED_MODULE_REGISTRY_H */ |