~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/registry.cc

pandora-build v0.71. Added check for avahi.

Show diffs side-by-side

added added

removed removed

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