~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
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
908.2.1 by Monty Taylor
First pass at refactoring plugins - factored out sql_map.
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
2234 by Brian Aker
Mass removal of ifdef/endif in favor of pragma once.
20
#pragma once
971.1.45 by Monty Taylor
Collapsed plugin_registry. _impl class not needed.
21
1130.1.2 by Monty Taylor
Re-org'd the replication stuff into slots.
22
#include <string>
23
#include <vector>
24
#include <map>
1192.2.8 by Monty Taylor
Updated plugin::Registry to use std::map instead of NameMap.
25
#include <algorithm>
2139.3.11 by Brian Aker
Error log messages from Inno, most, not all are sent to the correct error
26
#include <iostream>
1130.1.2 by Monty Taylor
Re-org'd the replication stuff into slots.
27
2095.3.7 by Monty Taylor
Fixed the dependency graph so that it doesn't get included in sql_yacc.yy.
28
#include <boost/scoped_ptr.hpp>
29
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
30
#include <drizzled/gettext.h>
31
#include <drizzled/unireg.h>
32
#include <drizzled/errmsg_print.h>
33
#include <drizzled/plugin/plugin.h>
2095.3.4 by Monty Taylor
Split out module vertex and then actually used it.
34
2095.3.2 by Monty Taylor
Add the depend graph to module::Registry.
35
971.1.49 by Monty Taylor
Hooked transaction_services into Plugin_registry.
36
namespace drizzled
37
{
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
38
39
namespace module
40
{
1192.2.3 by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity.
41
class Module;
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
42
class Library;
2095.3.7 by Monty Taylor
Fixed the dependency graph so that it doesn't get included in sql_yacc.yy.
43
class Graph;
971.1.46 by Monty Taylor
Made plugin registration go through Plugin_registry.
44
2095.3.2 by Monty Taylor
Add the depend graph to module::Registry.
45
1110.1.5 by Monty Taylor
Renamed PluginRegistry to plugin::Registry.
46
class Registry
908.2.1 by Monty Taylor
First pass at refactoring plugins - factored out sql_map.
47
{
2068.2.1 by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name
48
public:
2095.3.2 by Monty Taylor
Add the depend graph to module::Registry.
49
2068.2.1 by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name
50
  typedef std::map<std::string, Library *> LibraryMap;
51
  typedef std::map<std::string, Module *> ModuleMap;
2095.3.5 by Monty Taylor
Use the catalog registry.
52
  typedef std::vector<Module *> ModuleList;
908.2.1 by Monty Taylor
First pass at refactoring plugins - factored out sql_map.
53
private:
2068.2.1 by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name
54
  LibraryMap library_registry_;
55
  ModuleMap module_registry_;
2095.3.7 by Monty Taylor
Fixed the dependency graph so that it doesn't get included in sql_yacc.yy.
56
  boost::scoped_ptr<Graph> depend_graph_; 
2068.2.1 by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name
57
  
58
  plugin::Plugin::map plugin_registry;
1130.2.2 by Monty Taylor
Added support for the global list of plugin::Plugin objects to slot::Function
59
2095.3.6 by Monty Taylor
Actually properly process module dependencies. w00t.
60
  bool deps_built_;
61
2095.3.7 by Monty Taylor
Fixed the dependency graph so that it doesn't get included in sql_yacc.yy.
62
  Registry();
1110.1.5 by Monty Taylor
Renamed PluginRegistry to plugin::Registry.
63
  Registry(const Registry&);
1130.2.16 by Monty Taylor
Cleaned up the constructor initializer lists per Brian.
64
  Registry& operator=(const Registry&);
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
65
  ~Registry();
2095.3.2 by Monty Taylor
Add the depend graph to module::Registry.
66
2095.3.6 by Monty Taylor
Actually properly process module dependencies. w00t.
67
  void buildDeps();
908.2.1 by Monty Taylor
First pass at refactoring plugins - factored out sql_map.
68
public:
69
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
70
  static Registry& singleton()
1110.1.3 by Monty Taylor
Added ListenHandler as a member of PluginRegistry.
71
  {
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
72
    static Registry *registry= new Registry();
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
73
    return *registry;
74
  }
75
1966.2.6 by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing
76
  void copy(plugin::Plugin::vector &arg);
77
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
78
  static void shutdown();
1110.1.3 by Monty Taylor
Added ListenHandler as a member of PluginRegistry.
79
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
80
  Module *find(std::string name);
1192.2.3 by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity.
81
82
  void add(Module *module);
83
1702.4.1 by LinuxJedi
Remove module pointer from registry when module doesn't load to avoid a double-free on shutdown.
84
  void remove(Module *module);
1192.2.3 by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity.
85
2095.3.5 by Monty Taylor
Use the catalog registry.
86
  std::vector<Module *> getList();
971.1.52 by Monty Taylor
Did the finalizers. Renamed plugin_registry.
87
2068.2.1 by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name
88
  const plugin::Plugin::map &getPluginsMap() const
1192.2.8 by Monty Taylor
Updated plugin::Registry to use std::map instead of NameMap.
89
  {
90
    return plugin_registry;
1192.2.1 by Monty Taylor
Added the MODULES table.
91
  }
92
2068.2.1 by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name
93
  const ModuleMap &getModulesMap() const
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
94
  {
2068.2.1 by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name
95
    return module_registry_;
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
96
  }
97
1530.2.3 by Monty Taylor
Changed the builtin plugin code path to work exactly the same as dynamic.
98
  Library *addLibrary(const std::string &plugin_name, bool builtin= false);
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
99
  void removeLibrary(const std::string &plugin_name);
100
  Library *findLibrary(const std::string &plugin_name) const;
101
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
102
  void shutdownModules();
103
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
104
  template<class T>
105
  void add(T *plugin)
106
  {
1130.2.8 by Monty Taylor
Merged latest changes from plugin-slot-reorg.
107
    bool failed= false;
2068.2.1 by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name
108
    std::string plugin_type(plugin->getTypeName());
109
    std::transform(plugin_type.begin(), plugin_type.end(),
110
                   plugin_type.begin(), ::tolower);
1192.2.8 by Monty Taylor
Updated plugin::Registry to use std::map instead of NameMap.
111
    std::string plugin_name(plugin->getName());
112
    std::transform(plugin_name.begin(), plugin_name.end(),
113
                   plugin_name.begin(), ::tolower);
2068.2.1 by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name
114
    if (plugin_registry.find(std::make_pair(plugin_type, plugin_name)) != plugin_registry.end())
1192.2.8 by Monty Taylor
Updated plugin::Registry to use std::map instead of NameMap.
115
    {
2126.3.3 by Brian Aker
Merge in error message rework. Many error messages are fixed in this patch.
116
      errmsg_printf(error::ERROR,
2068.2.1 by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name
117
                    _("Loading plugin %s failed: a %s plugin by that name "
118
                      "already exists.\n"),
119
                    plugin->getTypeName().c_str(),
120
                    plugin->getName().c_str());
1130.2.8 by Monty Taylor
Merged latest changes from plugin-slot-reorg.
121
      failed= true;
1192.2.8 by Monty Taylor
Updated plugin::Registry to use std::map instead of NameMap.
122
    }
1130.2.8 by Monty Taylor
Merged latest changes from plugin-slot-reorg.
123
    if (T::addPlugin(plugin))
2068.2.1 by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name
124
    {
1130.2.8 by Monty Taylor
Merged latest changes from plugin-slot-reorg.
125
      failed= true;
2068.2.1 by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name
126
    }
127
1130.1.19 by Monty Taylor
Added error reporting to plugin registration.
128
    if (failed)
129
    {
2126.3.3 by Brian Aker
Merge in error message rework. Many error messages are fixed in this patch.
130
      errmsg_printf(error::ERROR,
2068.2.1 by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name
131
                    _("Fatal error: Failed initializing %s::%s plugin.\n"),
132
                    plugin->getTypeName().c_str(),
1192.2.8 by Monty Taylor
Updated plugin::Registry to use std::map instead of NameMap.
133
                    plugin->getName().c_str());
1130.1.19 by Monty Taylor
Added error reporting to plugin registration.
134
      unireg_abort(1);
135
    }
2068.2.1 by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name
136
    plugin_registry.insert(std::make_pair(std::make_pair(plugin_type, plugin_name), plugin));
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
137
  }
138
139
  template<class T>
140
  void remove(T *plugin)
141
  {
2068.2.1 by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name
142
    std::string plugin_type(plugin->getTypeName());
143
    std::transform(plugin_type.begin(), plugin_type.end(),
144
                   plugin_type.begin(), ::tolower);
1192.2.8 by Monty Taylor
Updated plugin::Registry to use std::map instead of NameMap.
145
    std::string plugin_name(plugin->getName());
146
    std::transform(plugin_name.begin(), plugin_name.end(),
147
                   plugin_name.begin(), ::tolower);
1130.1.18 by Monty Taylor
Changed ::add() and ::remove() to ::addPlugin() and ::removePlugin() so that
148
    T::removePlugin(plugin);
2068.2.1 by Monty Taylor
Changed the plugin_registry to store a pair of plugin_type/plugin_name
149
    plugin_registry.erase(std::make_pair(plugin_type, plugin_name));
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
150
  }
1130.1.8 by Monty Taylor
Added polymorphic add/remove methods around slot add/remove methods.
151
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
152
908.2.1 by Monty Taylor
First pass at refactoring plugins - factored out sql_map.
153
};
971.1.45 by Monty Taylor
Collapsed plugin_registry. _impl class not needed.
154
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
155
} /* namespace module */
156
} /* namespace drizzled */