~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/registry.cc

Merge Stewart's dead code removal

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"
21
 
 
22
 
#include <string>
23
 
#include <vector>
24
 
#include <map>
25
 
 
 
20
#include "drizzled/server_includes.h"
26
21
#include "drizzled/plugin/registry.h"
27
22
 
28
23
#include "drizzled/plugin.h"
29
 
#include "drizzled/plugin/library.h"
30
24
#include "drizzled/show.h"
31
25
#include "drizzled/cursor.h"
32
26
 
 
27
#include <string>
 
28
#include <vector>
 
29
#include <map>
 
30
 
33
31
using namespace std;
34
32
 
35
33
namespace drizzled
36
34
{
37
35
 
38
 
plugin::Registry::~Registry()
39
 
{
40
 
  map<string, plugin::Plugin *>::iterator plugin_iter= plugin_registry.begin();
41
 
  while (plugin_iter != plugin_registry.end())
42
 
  {
43
 
    delete (*plugin_iter).second;
44
 
    ++plugin_iter;
45
 
  }
46
 
  plugin_registry.clear();
47
 
 
48
 
  /*
49
 
    @TODO When we delete modules here, we segfault on a bad string. Why?
50
 
    map<string, plugin::Module *>::iterator module_iter= module_map.begin();
51
 
  while (module_iter != module_map.end())
52
 
  {
53
 
    delete (*module_iter).second;
54
 
    ++module_iter;
55
 
  }
56
 
  module_map.clear();
57
 
  */
58
 
  map<string, plugin::Library *>::iterator library_iter= library_map.begin();
59
 
  while (library_iter != library_map.end())
60
 
  {
61
 
    delete (*library_iter).second;
62
 
    ++library_iter;
63
 
  }
64
 
  library_map.clear();
65
 
}
66
 
 
67
 
void plugin::Registry::shutdown()
68
 
{
69
 
  plugin::Registry& registry= singleton();
70
 
  delete &registry;
71
 
}
72
 
 
73
 
plugin::Module *plugin::Registry::find(string name)
74
 
{
75
 
  transform(name.begin(), name.end(), name.begin(), ::tolower);
76
 
 
77
 
  map<string, plugin::Module *>::iterator map_iter;
78
 
  map_iter= module_map.find(name);
79
 
  if (map_iter != module_map.end())
 
36
plugin::Handle *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::Handle *>::iterator map_iter;
 
42
  map_iter= handle_map.find(find_str);
 
43
  if (map_iter != handle_map.end())
80
44
    return (*map_iter).second;
81
45
  return(0);
82
46
}
83
47
 
84
 
void plugin::Registry::add(plugin::Module *handle)
 
48
void plugin::Registry::add(plugin::Handle *handle)
85
49
{
86
50
  string add_str(handle->getName());
87
51
  transform(add_str.begin(), add_str.end(),
88
52
            add_str.begin(), ::tolower);
89
53
 
90
 
  module_map[add_str]= handle;
 
54
  handle_map[add_str]= handle;
91
55
}
92
56
 
93
57
 
94
 
vector<plugin::Module *> plugin::Registry::getList(bool active)
 
58
vector<plugin::Handle *> plugin::Registry::getList(bool active)
95
59
{
96
 
  plugin::Module *plugin= NULL;
97
 
 
98
 
  vector<plugin::Module *> plugins;
99
 
  plugins.reserve(module_map.size());
100
 
 
101
 
  map<string, plugin::Module *>::iterator map_iter;
102
 
  for (map_iter= module_map.begin();
103
 
       map_iter != module_map.end();
 
60
  plugin::Handle *plugin= NULL;
 
61
 
 
62
  vector <plugin::Handle *> plugins;
 
63
  plugins.reserve(handle_map.size());
 
64
 
 
65
  map<string, plugin::Handle *>::iterator map_iter;
 
66
  for (map_iter= handle_map.begin();
 
67
       map_iter != handle_map.end();
104
68
       map_iter++)
105
69
  {
106
70
    plugin= (*map_iter).second;
113
77
  return plugins;
114
78
}
115
79
 
116
 
plugin::Library *plugin::Registry::addLibrary(const string &plugin_name)
117
 
{
118
 
 
119
 
  /* If this dll is already loaded just return it */
120
 
  plugin::Library *library= findLibrary(plugin_name);
121
 
  if (library != NULL)
122
 
  {
123
 
    return library;
124
 
  }
125
 
 
126
 
  library= plugin::Library::loadLibrary(plugin_name);
127
 
  if (library != NULL)
128
 
  {
129
 
    /* Add this dll to the map */
130
 
    library_map.insert(make_pair(plugin_name, library));
131
 
  }
132
 
 
133
 
  return library;
134
 
}
135
 
 
136
 
void plugin::Registry::removeLibrary(const string &plugin_name)
137
 
{
138
 
  map<string, plugin::Library *>::iterator iter=
139
 
    library_map.find(plugin_name);
140
 
  if (iter != library_map.end())
141
 
  {
142
 
    library_map.erase(iter);
143
 
    delete (*iter).second;
144
 
  }
145
 
}
146
 
 
147
 
plugin::Library *plugin::Registry::findLibrary(const string &plugin_name) const
148
 
{
149
 
  map<string, plugin::Library *>::const_iterator iter=
150
 
    library_map.find(plugin_name);
151
 
  if (iter != library_map.end())
152
 
    return (*iter).second;
153
 
  return NULL;
154
 
}
155
 
 
156
80
} /* namespace drizzled */