~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/module/registry.cc

Renamed more stuff to drizzle.

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 "config.h"
21
 
 
22
 
#include <string>
23
 
#include <vector>
24
 
#include <map>
25
 
 
26
 
#include "drizzled/module/registry.h"
27
 
#include "drizzled/module/library.h"
28
 
 
29
 
#include "drizzled/plugin.h"
30
 
#include "drizzled/show.h"
31
 
#include "drizzled/cursor.h"
32
 
 
33
 
using namespace std;
34
 
 
35
 
namespace drizzled
36
 
{
37
 
 
38
 
 
39
 
module::Registry::~Registry()
40
 
{
41
 
  map<string, plugin::Plugin *>::iterator plugin_iter;
42
 
 
43
 
  /* Give all plugins a chance to cleanup, before
44
 
   * all plugins are deleted.
45
 
   * This can be used if shutdown code references
46
 
   * other plugins.
47
 
   */
48
 
  plugin_iter= plugin_registry.begin();
49
 
  while (plugin_iter != plugin_registry.end())
50
 
  {
51
 
    (*plugin_iter).second->shutdownPlugin();
52
 
    ++plugin_iter;
53
 
  }
54
 
 
55
 
  plugin_iter= plugin_registry.begin();
56
 
  while (plugin_iter != plugin_registry.end())
57
 
  {
58
 
    delete (*plugin_iter).second;
59
 
    ++plugin_iter;
60
 
  }
61
 
  plugin_registry.clear();
62
 
 
63
 
  /*
64
 
    @TODO When we delete modules here, we segfault on a bad string. Why?
65
 
    map<string, module::Module *>::iterator module_iter= module_map.begin();
66
 
  while (module_iter != module_map.end())
67
 
  {
68
 
    delete (*module_iter).second;
69
 
    ++module_iter;
70
 
  }
71
 
  module_map.clear();
72
 
  */
73
 
  map<string, module::Library *>::iterator library_iter= library_map.begin();
74
 
  while (library_iter != library_map.end())
75
 
  {
76
 
    delete (*library_iter).second;
77
 
    ++library_iter;
78
 
  }
79
 
  library_map.clear();
80
 
}
81
 
 
82
 
void module::Registry::shutdown()
83
 
{
84
 
  module::Registry& registry= singleton();
85
 
  delete &registry;
86
 
}
87
 
 
88
 
module::Module *module::Registry::find(string name)
89
 
{
90
 
  transform(name.begin(), name.end(), name.begin(), ::tolower);
91
 
 
92
 
  map<string, module::Module *>::iterator map_iter;
93
 
  map_iter= module_map.find(name);
94
 
  if (map_iter != module_map.end())
95
 
    return (*map_iter).second;
96
 
  return(0);
97
 
}
98
 
 
99
 
void module::Registry::add(module::Module *handle)
100
 
{
101
 
  string add_str(handle->getName());
102
 
  transform(add_str.begin(), add_str.end(),
103
 
            add_str.begin(), ::tolower);
104
 
 
105
 
  module_map[add_str]= handle;
106
 
}
107
 
 
108
 
void module::Registry::remove(module::Module *handle)
109
 
{
110
 
  string remove_str(handle->getName());
111
 
  transform(remove_str.begin(), remove_str.end(),
112
 
            remove_str.begin(), ::tolower);
113
 
 
114
 
  module_map.erase(remove_str);
115
 
}
116
 
 
117
 
vector<module::Module *> module::Registry::getList(bool active)
118
 
{
119
 
  module::Module *plugin= NULL;
120
 
 
121
 
  vector<module::Module *> plugins;
122
 
  plugins.reserve(module_map.size());
123
 
 
124
 
  map<string, module::Module *>::iterator map_iter;
125
 
  for (map_iter= module_map.begin();
126
 
       map_iter != module_map.end();
127
 
       map_iter++)
128
 
  {
129
 
    plugin= (*map_iter).second;
130
 
    if (active)
131
 
      plugins.push_back(plugin);
132
 
    else if (plugin->isInited)
133
 
      plugins.push_back(plugin);
134
 
  }
135
 
 
136
 
  return plugins;
137
 
}
138
 
 
139
 
module::Library *module::Registry::addLibrary(const string &plugin_name,
140
 
                                              bool builtin)
141
 
{
142
 
 
143
 
  /* If this dll is already loaded just return it */
144
 
  module::Library *library= findLibrary(plugin_name);
145
 
  if (library != NULL)
146
 
  {
147
 
    return library;
148
 
  }
149
 
 
150
 
  library= module::Library::loadLibrary(plugin_name, builtin);
151
 
  if (library != NULL)
152
 
  {
153
 
    /* Add this dll to the map */
154
 
    library_map.insert(make_pair(plugin_name, library));
155
 
  }
156
 
 
157
 
  return library;
158
 
}
159
 
 
160
 
void module::Registry::removeLibrary(const string &plugin_name)
161
 
{
162
 
  map<string, module::Library *>::iterator iter=
163
 
    library_map.find(plugin_name);
164
 
  if (iter != library_map.end())
165
 
  {
166
 
    library_map.erase(iter);
167
 
    delete (*iter).second;
168
 
  }
169
 
}
170
 
 
171
 
module::Library *module::Registry::findLibrary(const string &plugin_name) const
172
 
{
173
 
  map<string, module::Library *>::const_iterator iter=
174
 
    library_map.find(plugin_name);
175
 
  if (iter != library_map.end())
176
 
    return (*iter).second;
177
 
  return NULL;
178
 
}
179
 
 
180
 
void module::Registry::shutdownModules()
181
 
{
182
 
  module_shutdown(*this);
183
 
}
184
 
 
185
 
} /* namespace drizzled */