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 |
||
2234
by Brian Aker
Mass removal of ifdef/endif in favor of pragma once. |
20 |
#pragma once
|
971.1.45
by Monty Taylor
Collapsed plugin_registry. _impl class not needed. |
21 |
|
1130.1.2
by Monty Taylor
Re-org'd the replication stuff into slots. |
22 |
#include <string> |
23 |
#include <vector> |
|
24 |
#include <map> |
|
1192.2.8
by Monty Taylor
Updated plugin::Registry to use std::map instead of NameMap. |
25 |
#include <algorithm> |
2371.1.1
by Brian Aker
Fedora fix/use fwd header for iostream. |
26 |
#include <iosfwd> |
1130.1.2
by Monty Taylor
Re-org'd the replication stuff into slots. |
27 |
|
2282.1.5
by Olaf van der Spek
Refactor Module Registry |
28 |
#include <boost/algorithm/string.hpp> |
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 |
||
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
31 |
#include <drizzled/gettext.h> |
32 |
#include <drizzled/unireg.h> |
|
33 |
#include <drizzled/errmsg_print.h> |
|
34 |
#include <drizzled/plugin/plugin.h> |
|
2282.1.5
by Olaf van der Spek
Refactor Module Registry |
35 |
#include <drizzled/util/find_ptr.h> |
2095.3.2
by Monty Taylor
Add the depend graph to module::Registry. |
36 |
|
2252.1.21
by Olaf van der Spek
Common fwd |
37 |
namespace drizzled { |
38 |
namespace module { |
|
2095.3.2
by Monty Taylor
Add the depend graph to module::Registry. |
39 |
|
2282.1.3
by Olaf van der Spek
Refactor Module Registry |
40 |
class Registry : boost::noncopyable |
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
41 |
{
|
2068.2.1
by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name |
42 |
public: |
2282.1.3
by Olaf van der Spek
Refactor Module Registry |
43 |
typedef std::map<std::string, Library*> LibraryMap; |
44 |
typedef std::map<std::string, Module*> ModuleMap; |
|
45 |
typedef std::vector<Module*> ModuleList; |
|
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
46 |
private: |
2068.2.1
by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name |
47 |
LibraryMap library_registry_; |
48 |
ModuleMap module_registry_; |
|
2095.3.7
by Monty Taylor
Fixed the dependency graph so that it doesn't get included in sql_yacc.yy. |
49 |
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 |
50 |
|
51 |
plugin::Plugin::map plugin_registry; |
|
1130.2.2
by Monty Taylor
Added support for the global list of plugin::Plugin objects to slot::Function |
52 |
|
2095.3.6
by Monty Taylor
Actually properly process module dependencies. w00t. |
53 |
bool deps_built_; |
54 |
||
2095.3.7
by Monty Taylor
Fixed the dependency graph so that it doesn't get included in sql_yacc.yy. |
55 |
Registry(); |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
56 |
~Registry(); |
2095.3.2
by Monty Taylor
Add the depend graph to module::Registry. |
57 |
|
2095.3.6
by Monty Taylor
Actually properly process module dependencies. w00t. |
58 |
void buildDeps(); |
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 |
{
|
2282.1.5
by Olaf van der Spek
Refactor Module Registry |
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 |
|
2282.1.5
by Olaf van der Spek
Refactor Module Registry |
69 |
Module* find(const std::string&); |
70 |
||
71 |
void add(Module*); |
|
72 |
void remove(Module*); |
|
73 |
||
74 |
ModuleList getList(); |
|
971.1.52
by Monty Taylor
Did the finalizers. Renamed plugin_registry. |
75 |
|
2068.2.1
by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name |
76 |
const plugin::Plugin::map &getPluginsMap() const |
1192.2.8
by Monty Taylor
Updated plugin::Registry to use std::map instead of NameMap. |
77 |
{
|
78 |
return plugin_registry; |
|
1192.2.1
by Monty Taylor
Added the MODULES table. |
79 |
}
|
80 |
||
2068.2.1
by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name |
81 |
const ModuleMap &getModulesMap() const |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
82 |
{
|
2068.2.1
by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name |
83 |
return module_registry_; |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
84 |
}
|
85 |
||
1530.2.3
by Monty Taylor
Changed the builtin plugin code path to work exactly the same as dynamic. |
86 |
Library *addLibrary(const std::string &plugin_name, bool builtin= false); |
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
87 |
void removeLibrary(const std::string &plugin_name); |
88 |
Library *findLibrary(const std::string &plugin_name) const; |
|
89 |
||
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
90 |
void shutdownModules(); |
91 |
||
1130.1.12
by Monty Taylor
Moved service stuff into plugin/ |
92 |
template<class T> |
93 |
void add(T *plugin) |
|
94 |
{
|
|
1130.2.8
by Monty Taylor
Merged latest changes from plugin-slot-reorg. |
95 |
bool failed= false; |
2282.1.5
by Olaf van der Spek
Refactor Module Registry |
96 |
std::string plugin_type(boost::to_lower_copy(plugin->getTypeName())); |
97 |
std::string plugin_name(boost::to_lower_copy(plugin->getName())); |
|
98 |
if (find_ptr(plugin_registry, std::make_pair(plugin_type, plugin_name))) |
|
99 |
{
|
|
2363.1.6
by Brian Aker
Add better error messages for issues on startup. |
100 |
std::string error_message; |
101 |
error_message+= _("Loading plugin failed, a plugin by that name already exists."); |
|
102 |
error_message+= plugin->getTypeName(); |
|
103 |
error_message+= ":"; |
|
104 |
error_message+= plugin->getName(); |
|
105 |
unireg_actual_abort(__FILE__, __LINE__, __func__, error_message); |
|
106 |
}
|
|
107 |
||
108 |
if (T::addPlugin(plugin)) |
|
109 |
{
|
|
110 |
std::string error_message; |
|
111 |
error_message+= _("Fatal error: Failed initializing: "); |
|
112 |
error_message+= plugin->getTypeName(); |
|
113 |
error_message+= ":"; |
|
114 |
error_message+= plugin->getName(); |
|
115 |
unireg_actual_abort(__FILE__, __LINE__, __func__, error_message); |
|
116 |
}
|
|
2068.2.1
by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name |
117 |
|
1130.1.19
by Monty Taylor
Added error reporting to plugin registration. |
118 |
if (failed) |
119 |
{
|
|
2363.1.6
by Brian Aker
Add better error messages for issues on startup. |
120 |
unireg_abort << _("Fatal error: Failed initializing: ") << plugin->getTypeName() << ":" << plugin->getName(); |
1130.1.19
by Monty Taylor
Added error reporting to plugin registration. |
121 |
}
|
2068.2.1
by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name |
122 |
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/ |
123 |
}
|
124 |
||
125 |
template<class T> |
|
126 |
void remove(T *plugin) |
|
127 |
{
|
|
2282.1.5
by Olaf van der Spek
Refactor Module Registry |
128 |
std::string plugin_type(boost::to_lower_copy(plugin->getTypeName())); |
129 |
std::string plugin_name(boost::to_lower_copy(plugin->getName())); |
|
1130.1.18
by Monty Taylor
Changed ::add() and ::remove() to ::addPlugin() and ::removePlugin() so that |
130 |
T::removePlugin(plugin); |
2068.2.1
by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name |
131 |
plugin_registry.erase(std::make_pair(plugin_type, plugin_name)); |
1130.1.12
by Monty Taylor
Moved service stuff into plugin/ |
132 |
}
|
1130.1.8
by Monty Taylor
Added polymorphic add/remove methods around slot add/remove methods. |
133 |
|
1228.1.3
by Monty Taylor
All of the outstanding plugin loader system cleanups: |
134 |
|
908.2.1
by Monty Taylor
First pass at refactoring plugins - factored out sql_map. |
135 |
};
|
971.1.45
by Monty Taylor
Collapsed plugin_registry. _impl class not needed. |
136 |
|
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
137 |
} /* namespace module */ |
138 |
} /* namespace drizzled */ |