~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/registry.cc

  • Committer: Stewart Smith
  • Date: 2010-03-18 12:01:34 UTC
  • mto: (1666.2.3 build)
  • mto: This revision was merged to the branch mainline in revision 1596.
  • Revision ID: stewart@flamingspork.com-20100318120134-45fdnsw8g3j6c7oy
move RAND() into a plugin

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <vector>
24
24
#include <map>
25
25
 
26
 
#include "drizzled/module/registry.h"
27
 
#include "drizzled/module/library.h"
 
26
#include "drizzled/plugin/registry.h"
28
27
 
29
28
#include "drizzled/plugin.h"
 
29
#include "drizzled/plugin/library.h"
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
38
36
{
39
37
 
40
 
 
41
 
module::Registry::~Registry()
 
38
plugin::Registry::~Registry()
42
39
{
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;
 
40
  map<string, plugin::Library *>::iterator iter= library_map.begin();
 
41
  while (iter != library_map.end())
 
42
  {
 
43
    delete (*iter).second;
 
44
    ++iter;
81
45
  }
82
46
  library_map.clear();
83
47
}
84
48
 
85
 
void module::Registry::shutdown()
 
49
void plugin::Registry::shutdown()
86
50
{
87
 
  module::Registry& registry= singleton();
 
51
  plugin::Registry& registry= singleton();
88
52
  delete &registry;
89
53
}
90
54
 
91
 
module::Module *module::Registry::find(std::string name)
 
55
plugin::Module *plugin::Registry::find(string name)
92
56
{
93
 
  std::transform(name.begin(), name.end(), name.begin(), ::tolower);
 
57
  transform(name.begin(), name.end(), name.begin(), ::tolower);
94
58
 
95
 
  std::map<std::string, module::Module *>::iterator map_iter;
 
59
  map<string, plugin::Module *>::iterator map_iter;
96
60
  map_iter= module_map.find(name);
97
61
  if (map_iter != module_map.end())
98
62
    return (*map_iter).second;
99
63
  return(0);
100
64
}
101
65
 
102
 
void module::Registry::add(module::Module *handle)
 
66
void plugin::Registry::add(plugin::Module *handle)
103
67
{
104
 
  std::string add_str(handle->getName());
 
68
  string add_str(handle->getName());
105
69
  transform(add_str.begin(), add_str.end(),
106
70
            add_str.begin(), ::tolower);
107
71
 
108
72
  module_map[add_str]= handle;
109
73
}
110
74
 
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;
 
75
 
 
76
vector<plugin::Module *> plugin::Registry::getList(bool active)
 
77
{
 
78
  plugin::Module *plugin= NULL;
 
79
 
 
80
  vector<plugin::Module *> plugins;
136
81
  plugins.reserve(module_map.size());
137
82
 
138
 
  std::map<std::string, module::Module *>::iterator map_iter;
 
83
  map<string, plugin::Module *>::iterator map_iter;
139
84
  for (map_iter= module_map.begin();
140
85
       map_iter != module_map.end();
141
86
       map_iter++)
150
95
  return plugins;
151
96
}
152
97
 
153
 
module::Library *module::Registry::addLibrary(const std::string &plugin_name,
154
 
                                              bool builtin)
 
98
plugin::Library *plugin::Registry::addLibrary(const string &plugin_name)
155
99
{
156
100
 
157
101
  /* If this dll is already loaded just return it */
158
 
  module::Library *library= findLibrary(plugin_name);
 
102
  plugin::Library *library= findLibrary(plugin_name);
159
103
  if (library != NULL)
160
104
  {
161
105
    return library;
162
106
  }
163
107
 
164
 
  library= module::Library::loadLibrary(plugin_name, builtin);
 
108
  library= plugin::Library::loadLibrary(plugin_name);
165
109
  if (library != NULL)
166
110
  {
167
111
    /* Add this dll to the map */
171
115
  return library;
172
116
}
173
117
 
174
 
void module::Registry::removeLibrary(const std::string &plugin_name)
 
118
void plugin::Registry::removeLibrary(const string &plugin_name)
175
119
{
176
 
  std::map<std::string, module::Library *>::iterator iter=
 
120
  map<string, plugin::Library *>::iterator iter=
177
121
    library_map.find(plugin_name);
178
122
  if (iter != library_map.end())
179
123
  {
182
126
  }
183
127
}
184
128
 
185
 
module::Library *module::Registry::findLibrary(const std::string &plugin_name) const
 
129
plugin::Library *plugin::Registry::findLibrary(const string &plugin_name) const
186
130
{
187
 
  std::map<std::string, module::Library *>::const_iterator iter=
 
131
  map<string, plugin::Library *>::const_iterator iter=
188
132
    library_map.find(plugin_name);
189
133
  if (iter != library_map.end())
190
134
    return (*iter).second;
191
135
  return NULL;
192
136
}
193
137
 
194
 
void module::Registry::shutdownModules()
195
 
{
196
 
  module_shutdown(*this);
197
 
}
198
 
 
199
138
} /* namespace drizzled */