~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/module/registry.cc

  • Committer: Monty Taylor
  • Date: 2010-12-27 19:58:09 UTC
  • mto: This revision was merged to the branch mainline in revision 2038.
  • Revision ID: mordred@inaugust.com-20101227195809-1k7a4ge19l3u1o1h
Updated pandora-build files to version 0.171

Show diffs side-by-side

added added

removed removed

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