~drizzle-trunk/drizzle/development

908.2.1 by Monty Taylor
First pass at refactoring plugins - factored out sql_map.
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
1241.9.36 by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h.
20
#include "config.h"
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
21
22
#include <string>
23
#include <vector>
24
#include <map>
25
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
26
#include "drizzled/module/registry.h"
27
#include "drizzled/module/library.h"
908.2.1 by Monty Taylor
First pass at refactoring plugins - factored out sql_map.
28
29
#include "drizzled/plugin.h"
971.1.46 by Monty Taylor
Made plugin registration go through Plugin_registry.
30
#include "drizzled/show.h"
1183.1.2 by Brian Aker
Rename of handler to Cursor. You would not believe how long I have wanted
31
#include "drizzled/cursor.h"
908.2.1 by Monty Taylor
First pass at refactoring plugins - factored out sql_map.
32
33
using namespace std;
34
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
35
namespace drizzled
36
{
1110.1.5 by Monty Taylor
Renamed PluginRegistry to plugin::Registry.
37
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
38
39
module::Registry::~Registry()
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
40
{
1324.2.3 by Monty Taylor
Remove plugin deinit.
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
1324.2.4 by Monty Taylor
Turned off module deletion.
49
  /*
50
    @TODO When we delete modules here, we segfault on a bad string. Why?
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
51
    map<string, module::Module *>::iterator module_iter= module_map.begin();
1324.2.3 by Monty Taylor
Remove plugin deinit.
52
  while (module_iter != module_map.end())
53
  {
54
    delete (*module_iter).second;
55
    ++module_iter;
56
  }
57
  module_map.clear();
1324.2.4 by Monty Taylor
Turned off module deletion.
58
  */
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
59
  map<string, module::Library *>::iterator library_iter= library_map.begin();
1324.2.3 by Monty Taylor
Remove plugin deinit.
60
  while (library_iter != library_map.end())
61
  {
62
    delete (*library_iter).second;
63
    ++library_iter;
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
64
  }
65
  library_map.clear();
66
}
67
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
68
void module::Registry::shutdown()
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
69
{
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
70
  module::Registry& registry= singleton();
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
71
  delete &registry;
72
}
73
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
74
module::Module *module::Registry::find(string name)
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
75
{
76
  transform(name.begin(), name.end(), name.begin(), ::tolower);
908.2.1 by Monty Taylor
First pass at refactoring plugins - factored out sql_map.
77
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
78
  map<string, module::Module *>::iterator map_iter;
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
79
  map_iter= module_map.find(name);
1192.2.3 by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity.
80
  if (map_iter != module_map.end())
971.1.54 by Monty Taylor
Trimmed out some plugin type stuff.
81
    return (*map_iter).second;
908.2.1 by Monty Taylor
First pass at refactoring plugins - factored out sql_map.
82
  return(0);
83
}
84
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
85
void module::Registry::add(module::Module *handle)
908.2.1 by Monty Taylor
First pass at refactoring plugins - factored out sql_map.
86
{
1130.2.2 by Monty Taylor
Added support for the global list of plugin::Plugin objects to slot::Function
87
  string add_str(handle->getName());
908.2.1 by Monty Taylor
First pass at refactoring plugins - factored out sql_map.
88
  transform(add_str.begin(), add_str.end(),
89
            add_str.begin(), ::tolower);
90
1192.2.3 by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity.
91
  module_map[add_str]= handle;
1130.2.2 by Monty Taylor
Added support for the global list of plugin::Plugin objects to slot::Function
92
}
93
908.2.1 by Monty Taylor
First pass at refactoring plugins - factored out sql_map.
94
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
95
vector<module::Module *> module::Registry::getList(bool active)
908.2.1 by Monty Taylor
First pass at refactoring plugins - factored out sql_map.
96
{
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
97
  module::Module *plugin= NULL;
1192.2.3 by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity.
98
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
99
  vector<module::Module *> plugins;
1192.2.3 by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity.
100
  plugins.reserve(module_map.size());
101
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
102
  map<string, module::Module *>::iterator map_iter;
1192.2.3 by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity.
103
  for (map_iter= module_map.begin();
104
       map_iter != module_map.end();
908.2.1 by Monty Taylor
First pass at refactoring plugins - factored out sql_map.
105
       map_iter++)
106
  {
107
    plugin= (*map_iter).second;
965.1.1 by Brian Aker
Refactor plugin loading to remove mask (one step closer to getting rid of
108
    if (active)
109
      plugins.push_back(plugin);
110
    else if (plugin->isInited)
111
      plugins.push_back(plugin);
908.2.1 by Monty Taylor
First pass at refactoring plugins - factored out sql_map.
112
  }
971.1.54 by Monty Taylor
Trimmed out some plugin type stuff.
113
114
  return plugins;
908.2.1 by Monty Taylor
First pass at refactoring plugins - factored out sql_map.
115
}
971.1.46 by Monty Taylor
Made plugin registration go through Plugin_registry.
116
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
117
module::Library *module::Registry::addLibrary(const string &plugin_name,
1530.2.3 by Monty Taylor
Changed the builtin plugin code path to work exactly the same as dynamic.
118
                                              bool builtin)
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
119
{
120
121
  /* If this dll is already loaded just return it */
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
122
  module::Library *library= findLibrary(plugin_name);
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
123
  if (library != NULL)
124
  {
125
    return library;
126
  }
127
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
128
  library= module::Library::loadLibrary(plugin_name, builtin);
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
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
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
138
void module::Registry::removeLibrary(const string &plugin_name)
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
139
{
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
140
  map<string, module::Library *>::iterator iter=
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
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
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
149
module::Library *module::Registry::findLibrary(const string &plugin_name) const
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
150
{
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
151
  map<string, module::Library *>::const_iterator iter=
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
152
    library_map.find(plugin_name);
153
  if (iter != library_map.end())
154
    return (*iter).second;
155
  return NULL;
156
}
157
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
158
void module::Registry::shutdownModules()
159
{
160
  module_shutdown(*this);
161
}
162
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
163
} /* namespace drizzled */