~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/module/registry.cc

  • Committer: Monty Taylor
  • Date: 2010-09-28 07:45:44 UTC
  • mto: (1799.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1800.
  • Revision ID: mordred@inaugust.com-20100928074544-s3ujnv6s8wro74l2
Added BSD copying file.

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