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 |
||
971.1.45
by Monty Taylor
Collapsed plugin_registry. _impl class not needed. |
20 |
#ifndef DRIZZLED_PLUGIN_REGISTRY_H
|
21 |
#define DRIZZLED_PLUGIN_REGISTRY_H
|
|
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 |
{
|
|
1192.2.3
by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity. |
36 |
class Module; |
1130.2.2
by Monty Taylor
Added support for the global list of plugin::Plugin objects to slot::Function |
37 |
class Plugin; |
971.1.46
by Monty Taylor
Made plugin registration go through Plugin_registry. |
38 |
|
1110.1.5
by Monty Taylor
Renamed PluginRegistry to plugin::Registry. |
39 |
class Registry |
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
40 |
{
|
41 |
private: |
|
1192.2.3
by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity. |
42 |
std::map<std::string, Module *> module_map; |
1192.2.8
by Monty Taylor
Updated plugin::Registry to use std::map instead of NameMap. |
43 |
std::map<std::string, const Plugin *> plugin_registry; |
1130.2.2
by Monty Taylor
Added support for the global list of plugin::Plugin objects to slot::Function |
44 |
|
1192.2.3
by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity. |
45 |
Module *current_module; |
1130.2.2
by Monty Taylor
Added support for the global list of plugin::Plugin objects to slot::Function |
46 |
|
47 |
Registry() |
|
1192.2.3
by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity. |
48 |
: module_map(), |
1130.2.16
by Monty Taylor
Cleaned up the constructor initializer lists per Brian. |
49 |
plugin_registry(), |
1192.2.3
by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity. |
50 |
current_module(NULL) |
1130.2.2
by Monty Taylor
Added support for the global list of plugin::Plugin objects to slot::Function |
51 |
{ } |
52 |
||
1110.1.5
by Monty Taylor
Renamed PluginRegistry to plugin::Registry. |
53 |
Registry(const Registry&); |
1130.2.16
by Monty Taylor
Cleaned up the constructor initializer lists per Brian. |
54 |
Registry& operator=(const Registry&); |
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
55 |
public: |
56 |
||
1110.1.5
by Monty Taylor
Renamed PluginRegistry to plugin::Registry. |
57 |
static plugin::Registry& singleton() |
1110.1.3
by Monty Taylor
Added ListenHandler as a member of PluginRegistry. |
58 |
{
|
971.7.1
by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup. |
59 |
static plugin::Registry *registry= new plugin::Registry(); |
60 |
return *registry; |
|
61 |
}
|
|
62 |
||
63 |
static void shutdown() |
|
64 |
{
|
|
65 |
plugin::Registry& registry= singleton(); |
|
66 |
delete ®istry; |
|
1110.1.3
by Monty Taylor
Added ListenHandler as a member of PluginRegistry. |
67 |
}
|
68 |
||
1192.2.3
by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity. |
69 |
Module *find(const LEX_STRING *name); |
70 |
||
71 |
void add(Module *module); |
|
72 |
||
73 |
void setCurrentModule(Module *module) |
|
74 |
{
|
|
75 |
current_module= module; |
|
76 |
}
|
|
77 |
||
78 |
void clearCurrentModule() |
|
79 |
{
|
|
80 |
current_module= NULL; |
|
81 |
}
|
|
82 |
||
83 |
std::vector<Module *> getList(bool active); |
|
971.1.52
by Monty Taylor
Did the finalizers. Renamed plugin_registry. |
84 |
|
1192.2.8
by Monty Taylor
Updated plugin::Registry to use std::map instead of NameMap. |
85 |
const std::map<std::string, const Plugin *> &getPluginsMap() const |
86 |
{
|
|
87 |
return plugin_registry; |
|
1192.2.1
by Monty Taylor
Added the MODULES table. |
88 |
}
|
89 |
||
1130.1.12
by Monty Taylor
Moved service stuff into plugin/ |
90 |
template<class T> |
91 |
void add(T *plugin) |
|
92 |
{
|
|
1192.2.3
by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity. |
93 |
plugin->setModule(current_module); |
1130.2.8
by Monty Taylor
Merged latest changes from plugin-slot-reorg. |
94 |
bool failed= false; |
1192.2.8
by Monty Taylor
Updated plugin::Registry to use std::map instead of NameMap. |
95 |
std::string plugin_name(plugin->getName()); |
96 |
std::transform(plugin_name.begin(), plugin_name.end(), |
|
97 |
plugin_name.begin(), ::tolower); |
|
98 |
if (plugin_registry.find(plugin_name) != plugin_registry.end()) |
|
99 |
{
|
|
100 |
errmsg_printf(ERRMSG_LVL_ERROR, |
|
101 |
_("Loading plugin %s failed: a plugin by that name already " |
|
102 |
"exists."), plugin->getName().c_str()); |
|
1130.2.8
by Monty Taylor
Merged latest changes from plugin-slot-reorg. |
103 |
failed= true; |
1192.2.8
by Monty Taylor
Updated plugin::Registry to use std::map instead of NameMap. |
104 |
}
|
1130.2.8
by Monty Taylor
Merged latest changes from plugin-slot-reorg. |
105 |
if (T::addPlugin(plugin)) |
106 |
failed= true; |
|
1130.1.19
by Monty Taylor
Added error reporting to plugin registration. |
107 |
if (failed) |
108 |
{
|
|
1192.2.8
by Monty Taylor
Updated plugin::Registry to use std::map instead of NameMap. |
109 |
errmsg_printf(ERRMSG_LVL_ERROR, |
110 |
_("Fatal error: Failed initializing %s plugin."), |
|
111 |
plugin->getName().c_str()); |
|
1130.1.19
by Monty Taylor
Added error reporting to plugin registration. |
112 |
unireg_abort(1); |
113 |
}
|
|
1192.3.7
by Monty Taylor
Added code necessary for building plugins dynamically. |
114 |
plugin_registry.insert(std::pair<std::string, const Plugin *>(plugin_name, plugin)); |
1130.1.12
by Monty Taylor
Moved service stuff into plugin/ |
115 |
}
|
116 |
||
117 |
template<class T> |
|
118 |
void remove(T *plugin) |
|
119 |
{
|
|
1192.2.8
by Monty Taylor
Updated plugin::Registry to use std::map instead of NameMap. |
120 |
std::string plugin_name(plugin->getName()); |
121 |
std::transform(plugin_name.begin(), plugin_name.end(), |
|
122 |
plugin_name.begin(), ::tolower); |
|
1130.1.18
by Monty Taylor
Changed ::add() and ::remove() to ::addPlugin() and ::removePlugin() so that |
123 |
T::removePlugin(plugin); |
1192.2.8
by Monty Taylor
Updated plugin::Registry to use std::map instead of NameMap. |
124 |
plugin_registry.erase(plugin_name); |
1130.1.12
by Monty Taylor
Moved service stuff into plugin/ |
125 |
}
|
1130.1.8
by Monty Taylor
Added polymorphic add/remove methods around slot add/remove methods. |
126 |
|
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
127 |
};
|
971.1.45
by Monty Taylor
Collapsed plugin_registry. _impl class not needed. |
128 |
|
1110.1.5
by Monty Taylor
Renamed PluginRegistry to plugin::Registry. |
129 |
} /* end namespace plugin */ |
130 |
} /* end namespace drizzled */ |
|
971.1.45
by Monty Taylor
Collapsed plugin_registry. _impl class not needed. |
131 |
#endif /* DRIZZLED_PLUGIN_REGISTRY_H */ |