~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/module/registry.cc

  • Committer: Brian Aker
  • Date: 2010-05-27 01:25:56 UTC
  • mfrom: (1567.1.4 new-staging)
  • Revision ID: brian@gaz-20100527012556-5zgkirkl7swbigd6
Merge of Brian, Paul. PBXT compile issue, and test framework cleanup. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 Sun Microsystems
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; version 2 of the License.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
 
19
 
 
20
#include "config.h"
 
21
 
 
22
#include <string>
 
23
#include <vector>
 
24
#include <map>
 
25
 
 
26
#include "drizzled/module/registry.h"
 
27
#include "drizzled/module/library.h"
 
28
 
 
29
#include "drizzled/plugin.h"
 
30
#include "drizzled/show.h"
 
31
#include "drizzled/cursor.h"
 
32
 
 
33
using namespace std;
 
34
 
 
35
namespace drizzled
 
36
{
 
37
 
 
38
 
 
39
module::Registry::~Registry()
 
40
{
 
41
  map<string, plugin::Plugin *>::iterator plugin_iter= plugin_registry.begin();
 
42
  while (plugin_iter != plugin_registry.end())
 
43
  {
 
44
    delete (*plugin_iter).second;
 
45
    ++plugin_iter;
 
46
  }
 
47
  plugin_registry.clear();
 
48
 
 
49
  /*
 
50
    @TODO When we delete modules here, we segfault on a bad string. Why?
 
51
    map<string, module::Module *>::iterator module_iter= module_map.begin();
 
52
  while (module_iter != module_map.end())
 
53
  {
 
54
    delete (*module_iter).second;
 
55
    ++module_iter;
 
56
  }
 
57
  module_map.clear();
 
58
  */
 
59
  map<string, module::Library *>::iterator library_iter= library_map.begin();
 
60
  while (library_iter != library_map.end())
 
61
  {
 
62
    delete (*library_iter).second;
 
63
    ++library_iter;
 
64
  }
 
65
  library_map.clear();
 
66
}
 
67
 
 
68
void module::Registry::shutdown()
 
69
{
 
70
  module::Registry& registry= singleton();
 
71
  delete &registry;
 
72
}
 
73
 
 
74
module::Module *module::Registry::find(string name)
 
75
{
 
76
  transform(name.begin(), name.end(), name.begin(), ::tolower);
 
77
 
 
78
  map<string, module::Module *>::iterator map_iter;
 
79
  map_iter= module_map.find(name);
 
80
  if (map_iter != module_map.end())
 
81
    return (*map_iter).second;
 
82
  return(0);
 
83
}
 
84
 
 
85
void module::Registry::add(module::Module *handle)
 
86
{
 
87
  string add_str(handle->getName());
 
88
  transform(add_str.begin(), add_str.end(),
 
89
            add_str.begin(), ::tolower);
 
90
 
 
91
  module_map[add_str]= handle;
 
92
}
 
93
 
 
94
 
 
95
vector<module::Module *> module::Registry::getList(bool active)
 
96
{
 
97
  module::Module *plugin= NULL;
 
98
 
 
99
  vector<module::Module *> plugins;
 
100
  plugins.reserve(module_map.size());
 
101
 
 
102
  map<string, module::Module *>::iterator map_iter;
 
103
  for (map_iter= module_map.begin();
 
104
       map_iter != module_map.end();
 
105
       map_iter++)
 
106
  {
 
107
    plugin= (*map_iter).second;
 
108
    if (active)
 
109
      plugins.push_back(plugin);
 
110
    else if (plugin->isInited)
 
111
      plugins.push_back(plugin);
 
112
  }
 
113
 
 
114
  return plugins;
 
115
}
 
116
 
 
117
module::Library *module::Registry::addLibrary(const string &plugin_name,
 
118
                                              bool builtin)
 
119
{
 
120
 
 
121
  /* If this dll is already loaded just return it */
 
122
  module::Library *library= findLibrary(plugin_name);
 
123
  if (library != NULL)
 
124
  {
 
125
    return library;
 
126
  }
 
127
 
 
128
  library= module::Library::loadLibrary(plugin_name, builtin);
 
129
  if (library != NULL)
 
130
  {
 
131
    /* Add this dll to the map */
 
132
    library_map.insert(make_pair(plugin_name, library));
 
133
  }
 
134
 
 
135
  return library;
 
136
}
 
137
 
 
138
void module::Registry::removeLibrary(const string &plugin_name)
 
139
{
 
140
  map<string, module::Library *>::iterator iter=
 
141
    library_map.find(plugin_name);
 
142
  if (iter != library_map.end())
 
143
  {
 
144
    library_map.erase(iter);
 
145
    delete (*iter).second;
 
146
  }
 
147
}
 
148
 
 
149
module::Library *module::Registry::findLibrary(const string &plugin_name) const
 
150
{
 
151
  map<string, module::Library *>::const_iterator iter=
 
152
    library_map.find(plugin_name);
 
153
  if (iter != library_map.end())
 
154
    return (*iter).second;
 
155
  return NULL;
 
156
}
 
157
 
 
158
void module::Registry::shutdownModules()
 
159
{
 
160
  module_shutdown(*this);
 
161
}
 
162
 
 
163
} /* namespace drizzled */