~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/module/registry.cc

Possible solution to longjump clobber problem.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include "drizzled/show.h"
31
31
#include "drizzled/cursor.h"
32
32
 
33
 
#include <boost/bind.hpp>
34
 
 
35
33
using namespace std;
36
34
 
37
35
namespace drizzled
40
38
 
41
39
module::Registry::~Registry()
42
40
{
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();
 
41
  map<string, plugin::Plugin *>::iterator plugin_iter= plugin_registry.begin();
58
42
  while (plugin_iter != plugin_registry.end())
59
43
  {
60
44
    delete (*plugin_iter).second;
62
46
  }
63
47
  plugin_registry.clear();
64
48
 
65
 
#if 0
66
 
  @TODO When we delete modules here, we segfault on a bad string. Why?
 
49
  /*
 
50
    @TODO When we delete modules here, we segfault on a bad string. Why?
67
51
    map<string, module::Module *>::iterator module_iter= module_map.begin();
68
 
 
69
52
  while (module_iter != module_map.end())
70
53
  {
71
54
    delete (*module_iter).second;
72
55
    ++module_iter;
73
56
  }
74
57
  module_map.clear();
75
 
#endif
76
 
  std::map<std::string, module::Library *>::iterator library_iter= library_map.begin();
 
58
  */
 
59
  map<string, module::Library *>::iterator library_iter= library_map.begin();
77
60
  while (library_iter != library_map.end())
78
61
  {
79
62
    delete (*library_iter).second;
88
71
  delete &registry;
89
72
}
90
73
 
91
 
module::Module *module::Registry::find(std::string name)
 
74
module::Module *module::Registry::find(string name)
92
75
{
93
 
  std::transform(name.begin(), name.end(), name.begin(), ::tolower);
 
76
  transform(name.begin(), name.end(), name.begin(), ::tolower);
94
77
 
95
 
  std::map<std::string, module::Module *>::iterator map_iter;
 
78
  map<string, module::Module *>::iterator map_iter;
96
79
  map_iter= module_map.find(name);
97
80
  if (map_iter != module_map.end())
98
81
    return (*map_iter).second;
101
84
 
102
85
void module::Registry::add(module::Module *handle)
103
86
{
104
 
  std::string add_str(handle->getName());
 
87
  string add_str(handle->getName());
105
88
  transform(add_str.begin(), add_str.end(),
106
89
            add_str.begin(), ::tolower);
107
90
 
108
91
  module_map[add_str]= handle;
109
92
}
110
93
 
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
94
 
131
95
vector<module::Module *> module::Registry::getList(bool active)
132
96
{
133
97
  module::Module *plugin= NULL;
134
98
 
135
 
  std::vector<module::Module *> plugins;
 
99
  vector<module::Module *> plugins;
136
100
  plugins.reserve(module_map.size());
137
101
 
138
 
  std::map<std::string, module::Module *>::iterator map_iter;
 
102
  map<string, module::Module *>::iterator map_iter;
139
103
  for (map_iter= module_map.begin();
140
104
       map_iter != module_map.end();
141
105
       map_iter++)
150
114
  return plugins;
151
115
}
152
116
 
153
 
module::Library *module::Registry::addLibrary(const std::string &plugin_name,
 
117
module::Library *module::Registry::addLibrary(const string &plugin_name,
154
118
                                              bool builtin)
155
119
{
156
120
 
171
135
  return library;
172
136
}
173
137
 
174
 
void module::Registry::removeLibrary(const std::string &plugin_name)
 
138
void module::Registry::removeLibrary(const string &plugin_name)
175
139
{
176
 
  std::map<std::string, module::Library *>::iterator iter=
 
140
  map<string, module::Library *>::iterator iter=
177
141
    library_map.find(plugin_name);
178
142
  if (iter != library_map.end())
179
143
  {
182
146
  }
183
147
}
184
148
 
185
 
module::Library *module::Registry::findLibrary(const std::string &plugin_name) const
 
149
module::Library *module::Registry::findLibrary(const string &plugin_name) const
186
150
{
187
 
  std::map<std::string, module::Library *>::const_iterator iter=
 
151
  map<string, module::Library *>::const_iterator iter=
188
152
    library_map.find(plugin_name);
189
153
  if (iter != library_map.end())
190
154
    return (*iter).second;