~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin_registry.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-06-29 17:24:02 UTC
  • mto: This revision was merged to the branch mainline in revision 1081.
  • Revision ID: osullivan.padraig@gmail.com-20090629172402-9c5n1kr7ry7xgau7
Removed the dependency on knowing the position of an I_S table in the
schema_tables array defined in show.cc. This issue crops up in
prepare_schema_table. An issue with my design is that it increases the time
complexity from O(1) to O(n) in numerous places to determine an I_S table to
work on since we don't have an explicit index into the array and instead
need to search by name. However, as n is the number of I_S tables and this
number is quite small (at the moment n is < 30), we don't see this causing
any issue. This design makes the code much more maintainable and easier to
understand. Previously, modifying anything to do with the I_S tables meant
having to tip-toe around the issue of hard-coded indexes into the
schema_tables array.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
20
#include "drizzled/server_includes.h"
 
21
#include "drizzled/plugin_registry.h"
 
22
 
 
23
#include "drizzled/plugin.h"
 
24
#include "drizzled/show.h"
 
25
#include "drizzled/handler.h"
 
26
#include "drizzled/errmsg.h"
 
27
#include "drizzled/authentication.h"
 
28
#include "drizzled/qcache.h"
 
29
#include "drizzled/scheduling.h"
 
30
#include "drizzled/logging.h"
 
31
#include "drizzled/sql_udf.h"
 
32
#include "drizzled/listen.h"
 
33
#include "drizzled/transaction_services.h"
 
34
 
 
35
#include <string>
 
36
#include <vector>
 
37
#include <map>
 
38
 
 
39
using namespace std;
 
40
 
 
41
static PluginRegistry the_registry;
 
42
 
 
43
PluginRegistry& PluginRegistry::getPluginRegistry()
 
44
{
 
45
  return the_registry;
 
46
}
 
47
 
 
48
st_plugin_int *PluginRegistry::find(const LEX_STRING *name)
 
49
{
 
50
  string find_str(name->str,name->length);
 
51
  transform(find_str.begin(), find_str.end(), find_str.begin(), ::tolower);
 
52
 
 
53
  map<string, st_plugin_int *>::iterator map_iter;
 
54
  map_iter= plugin_map.find(find_str);
 
55
  if (map_iter != plugin_map.end())
 
56
    return (*map_iter).second;
 
57
  return(0);
 
58
}
 
59
 
 
60
void PluginRegistry::add(st_plugin_int *plugin)
 
61
{
 
62
  string add_str(plugin->name.str);
 
63
  transform(add_str.begin(), add_str.end(),
 
64
            add_str.begin(), ::tolower);
 
65
 
 
66
  plugin_map[add_str]= plugin;
 
67
}
 
68
 
 
69
 
 
70
vector<st_plugin_int *> PluginRegistry::get_list(bool active)
 
71
{
 
72
  st_plugin_int *plugin= NULL;
 
73
 
 
74
  vector <st_plugin_int *> plugins;
 
75
  plugins.reserve(plugin_map.size());
 
76
 
 
77
  map<string, st_plugin_int *>::iterator map_iter;
 
78
  for (map_iter= plugin_map.begin();
 
79
       map_iter != plugin_map.end();
 
80
       map_iter++)
 
81
  {
 
82
    plugin= (*map_iter).second;
 
83
    if (active)
 
84
      plugins.push_back(plugin);
 
85
    else if (plugin->isInited)
 
86
      plugins.push_back(plugin);
 
87
  }
 
88
 
 
89
  return plugins;
 
90
}
 
91
 
 
92
void PluginRegistry::add(StorageEngine *engine)
 
93
{
 
94
  add_storage_engine(engine);
 
95
}
 
96
 
 
97
void PluginRegistry::add(InfoSchemaTable *schema_table)
 
98
{
 
99
  add_infoschema_table(schema_table);
 
100
}
 
101
 
 
102
void PluginRegistry::add(Function_builder *udf)
 
103
{
 
104
  add_udf(udf);
 
105
}
 
106
 
 
107
void PluginRegistry::add(Logging_handler *handler)
 
108
{
 
109
  add_logger(handler);
 
110
}
 
111
 
 
112
void PluginRegistry::add(Error_message_handler *handler)
 
113
{
 
114
  add_errmsg_handler(handler);
 
115
}
 
116
 
 
117
void PluginRegistry::add(Authentication *auth)
 
118
{
 
119
  add_authentication(auth);
 
120
}
 
121
 
 
122
void PluginRegistry::add(QueryCache *qcache)
 
123
{
 
124
  add_query_cache(qcache);
 
125
}
 
126
 
 
127
void PluginRegistry::add(SchedulerFactory *factory)
 
128
{
 
129
  add_scheduler_factory(factory);
 
130
}
 
131
 
 
132
void PluginRegistry::add(const Listen &listen_obj)
 
133
{
 
134
  add_listen(listen_obj);
 
135
}
 
136
 
 
137
void PluginRegistry::add(drizzled::plugin::Replicator *repl)
 
138
{
 
139
  add_replicator(repl);
 
140
}
 
141
 
 
142
void PluginRegistry::remove(StorageEngine *engine)
 
143
{
 
144
  remove_storage_engine(engine);
 
145
}
 
146
 
 
147
void PluginRegistry::remove(InfoSchemaTable *schema_table)
 
148
{
 
149
  remove_infoschema_table(schema_table);
 
150
}
 
151
 
 
152
void PluginRegistry::remove(Function_builder *udf)
 
153
{
 
154
  remove_udf(udf);
 
155
}
 
156
 
 
157
void PluginRegistry::remove(Logging_handler *handler)
 
158
{
 
159
  remove_logger(handler);
 
160
}
 
161
 
 
162
void PluginRegistry::remove(Error_message_handler *handler)
 
163
{
 
164
  remove_errmsg_handler(handler);
 
165
}
 
166
 
 
167
void PluginRegistry::remove(Authentication *auth)
 
168
{
 
169
  remove_authentication(auth);
 
170
}
 
171
 
 
172
void PluginRegistry::remove(QueryCache *qcache)
 
173
{
 
174
  remove_query_cache(qcache);
 
175
}
 
176
 
 
177
void PluginRegistry::remove(SchedulerFactory *factory)
 
178
{
 
179
  remove_scheduler_factory(factory);
 
180
}
 
181
 
 
182
void PluginRegistry::remove(const Listen &listen_obj)
 
183
{
 
184
  remove_listen(listen_obj);
 
185
}
 
186
 
 
187
void PluginRegistry::remove(drizzled::plugin::Replicator *repl)
 
188
{
 
189
  remove_replicator(repl);
 
190
}