~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/module/registry.cc

  • Committer: Stewart Smith
  • Date: 2010-11-03 03:27:09 UTC
  • mto: (1902.1.1 build) (1910.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1903.
  • Revision ID: stewart@flamingspork.com-20101103032709-oyvfrc6eb8fzj0mr
fix docs warning: docs/unlock.rst:2: (WARNING/2) Title underline too short.

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::Plugin *>::iterator plugin_iter= plugin_registry.begin();
 
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();
41
56
  while (plugin_iter != plugin_registry.end())
42
57
  {
43
58
    delete (*plugin_iter).second;
47
62
 
48
63
  /*
49
64
    @TODO When we delete modules here, we segfault on a bad string. Why?
50
 
    map<string, plugin::Module *>::iterator module_iter= module_map.begin();
 
65
    map<string, module::Module *>::iterator module_iter= module_map.begin();
51
66
  while (module_iter != module_map.end())
52
67
  {
53
68
    delete (*module_iter).second;
55
70
  }
56
71
  module_map.clear();
57
72
  */
58
 
  map<string, plugin::Library *>::iterator library_iter= library_map.begin();
 
73
  map<string, module::Library *>::iterator library_iter= library_map.begin();
59
74
  while (library_iter != library_map.end())
60
75
  {
61
76
    delete (*library_iter).second;
64
79
  library_map.clear();
65
80
}
66
81
 
67
 
void plugin::Registry::shutdown()
 
82
void module::Registry::shutdown()
68
83
{
69
 
  plugin::Registry& registry= singleton();
 
84
  module::Registry& registry= singleton();
70
85
  delete &registry;
71
86
}
72
87
 
73
 
plugin::Module *plugin::Registry::find(string name)
 
88
module::Module *module::Registry::find(string name)
74
89
{
75
90
  transform(name.begin(), name.end(), name.begin(), ::tolower);
76
91
 
77
 
  map<string, plugin::Module *>::iterator map_iter;
 
92
  map<string, module::Module *>::iterator map_iter;
78
93
  map_iter= module_map.find(name);
79
94
  if (map_iter != module_map.end())
80
95
    return (*map_iter).second;
81
96
  return(0);
82
97
}
83
98
 
84
 
void plugin::Registry::add(plugin::Module *handle)
 
99
void module::Registry::add(module::Module *handle)
85
100
{
86
101
  string add_str(handle->getName());
87
102
  transform(add_str.begin(), add_str.end(),
90
105
  module_map[add_str]= handle;
91
106
}
92
107
 
93
 
 
94
 
vector<plugin::Module *> plugin::Registry::getList(bool active)
95
 
{
96
 
  plugin::Module *plugin= NULL;
97
 
 
98
 
  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;
99
122
  plugins.reserve(module_map.size());
100
123
 
101
 
  map<string, plugin::Module *>::iterator map_iter;
 
124
  map<string, module::Module *>::iterator map_iter;
102
125
  for (map_iter= module_map.begin();
103
126
       map_iter != module_map.end();
104
127
       map_iter++)
113
136
  return plugins;
114
137
}
115
138
 
116
 
plugin::Library *plugin::Registry::addLibrary(const string &plugin_name)
 
139
module::Library *module::Registry::addLibrary(const string &plugin_name,
 
140
                                              bool builtin)
117
141
{
118
142
 
119
143
  /* If this dll is already loaded just return it */
120
 
  plugin::Library *library= findLibrary(plugin_name);
 
144
  module::Library *library= findLibrary(plugin_name);
121
145
  if (library != NULL)
122
146
  {
123
147
    return library;
124
148
  }
125
149
 
126
 
  library= plugin::Library::loadLibrary(plugin_name);
 
150
  library= module::Library::loadLibrary(plugin_name, builtin);
127
151
  if (library != NULL)
128
152
  {
129
153
    /* Add this dll to the map */
133
157
  return library;
134
158
}
135
159
 
136
 
void plugin::Registry::removeLibrary(const string &plugin_name)
 
160
void module::Registry::removeLibrary(const string &plugin_name)
137
161
{
138
 
  map<string, plugin::Library *>::iterator iter=
 
162
  map<string, module::Library *>::iterator iter=
139
163
    library_map.find(plugin_name);
140
164
  if (iter != library_map.end())
141
165
  {
144
168
  }
145
169
}
146
170
 
147
 
plugin::Library *plugin::Registry::findLibrary(const string &plugin_name) const
 
171
module::Library *module::Registry::findLibrary(const string &plugin_name) const
148
172
{
149
 
  map<string, plugin::Library *>::const_iterator iter=
 
173
  map<string, module::Library *>::const_iterator iter=
150
174
    library_map.find(plugin_name);
151
175
  if (iter != library_map.end())
152
176
    return (*iter).second;
153
177
  return NULL;
154
178
}
155
179
 
 
180
void module::Registry::shutdownModules()
 
181
{
 
182
  module_shutdown(*this);
 
183
}
 
184
 
156
185
} /* namespace drizzled */