~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin_registry.h

  • Committer: Brian Aker
  • Date: 2009-06-26 00:37:27 UTC
  • Revision ID: brian@gaz-20090626003727-b2y4gitpptzbvypd
Fix for CentOS

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, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
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
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#ifndef DRIZZLED_MODULE_REGISTRY_H
21
 
#define DRIZZLED_MODULE_REGISTRY_H
 
20
#ifndef DRIZZLED_PLUGIN_REGISTRY_H
 
21
#define DRIZZLED_PLUGIN_REGISTRY_H
 
22
 
22
23
 
23
24
#include <string>
24
25
#include <vector>
25
26
#include <map>
26
 
#include <algorithm>
27
 
#include <iostream>
28
 
 
29
 
#include <boost/scoped_ptr.hpp>
30
 
 
31
 
#include "drizzled/gettext.h"
32
 
#include "drizzled/unireg.h"
33
 
#include "drizzled/errmsg_print.h"
34
 
#include "drizzled/plugin/plugin.h"
35
 
 
36
 
 
 
27
 
 
28
struct st_plugin_int;
 
29
class StorageEngine;
 
30
class InfoSchemaTable;
 
31
class Function_builder;
 
32
class Logging_handler;
 
33
class Error_message_handler;
 
34
class Authentication;
 
35
class QueryCache;
 
36
class SchedulerFactory;
 
37
class ProtocolFactory;
37
38
namespace drizzled
38
39
{
39
 
 
40
 
namespace module
41
 
{
42
 
class Module;
43
 
class Library;
44
 
class Graph;
45
 
 
46
 
 
47
 
class Registry
48
 
{
49
 
public:
50
 
 
51
 
  typedef std::map<std::string, Library *> LibraryMap;
52
 
  typedef std::map<std::string, Module *> ModuleMap;
53
 
  typedef std::vector<Module *> ModuleList;
 
40
namespace plugin
 
41
{
 
42
class Replicator;
 
43
}
 
44
}
 
45
 
 
46
class PluginRegistry
 
47
{
54
48
private:
55
 
  LibraryMap library_registry_;
56
 
  ModuleMap module_registry_;
57
 
  boost::scoped_ptr<Graph> depend_graph_; 
58
 
  
59
 
  plugin::Plugin::map plugin_registry;
60
 
 
61
 
  bool deps_built_;
62
 
 
63
 
  Registry();
64
 
  Registry(const Registry&);
65
 
  Registry& operator=(const Registry&);
66
 
  ~Registry();
67
 
 
68
 
  void buildDeps();
 
49
  std::map<std::string, st_plugin_int *>
 
50
    plugin_map;
 
51
 
 
52
  PluginRegistry(const PluginRegistry&);
69
53
public:
70
 
 
71
 
  static Registry& singleton()
72
 
  {
73
 
    static Registry *registry= new Registry();
74
 
    return *registry;
75
 
  }
76
 
 
77
 
  void copy(plugin::Plugin::vector &arg);
78
 
 
79
 
  static void shutdown();
80
 
 
81
 
  Module *find(std::string name);
82
 
 
83
 
  void add(Module *module);
84
 
 
85
 
  void remove(Module *module);
86
 
 
87
 
  std::vector<Module *> getList();
88
 
 
89
 
  const plugin::Plugin::map &getPluginsMap() const
90
 
  {
91
 
    return plugin_registry;
92
 
  }
93
 
 
94
 
  const ModuleMap &getModulesMap() const
95
 
  {
96
 
    return module_registry_;
97
 
  }
98
 
 
99
 
  Library *addLibrary(const std::string &plugin_name, bool builtin= false);
100
 
  void removeLibrary(const std::string &plugin_name);
101
 
  Library *findLibrary(const std::string &plugin_name) const;
102
 
 
103
 
  void shutdownModules();
104
 
 
105
 
  template<class T>
106
 
  void add(T *plugin)
107
 
  {
108
 
    bool failed= false;
109
 
    std::string plugin_type(plugin->getTypeName());
110
 
    std::transform(plugin_type.begin(), plugin_type.end(),
111
 
                   plugin_type.begin(), ::tolower);
112
 
    std::string plugin_name(plugin->getName());
113
 
    std::transform(plugin_name.begin(), plugin_name.end(),
114
 
                   plugin_name.begin(), ::tolower);
115
 
    if (plugin_registry.find(std::make_pair(plugin_type, plugin_name)) != plugin_registry.end())
116
 
    {
117
 
      errmsg_printf(error::ERROR,
118
 
                    _("Loading plugin %s failed: a %s plugin by that name "
119
 
                      "already exists.\n"),
120
 
                    plugin->getTypeName().c_str(),
121
 
                    plugin->getName().c_str());
122
 
      failed= true;
123
 
    }
124
 
    if (T::addPlugin(plugin))
125
 
    {
126
 
      failed= true;
127
 
    }
128
 
 
129
 
    if (failed)
130
 
    {
131
 
      errmsg_printf(error::ERROR,
132
 
                    _("Fatal error: Failed initializing %s::%s plugin.\n"),
133
 
                    plugin->getTypeName().c_str(),
134
 
                    plugin->getName().c_str());
135
 
      unireg_abort(1);
136
 
    }
137
 
    plugin_registry.insert(std::make_pair(std::make_pair(plugin_type, plugin_name), plugin));
138
 
  }
139
 
 
140
 
  template<class T>
141
 
  void remove(T *plugin)
142
 
  {
143
 
    std::string plugin_type(plugin->getTypeName());
144
 
    std::transform(plugin_type.begin(), plugin_type.end(),
145
 
                   plugin_type.begin(), ::tolower);
146
 
    std::string plugin_name(plugin->getName());
147
 
    std::transform(plugin_name.begin(), plugin_name.end(),
148
 
                   plugin_name.begin(), ::tolower);
149
 
    T::removePlugin(plugin);
150
 
    plugin_registry.erase(std::make_pair(plugin_type, plugin_name));
151
 
  }
152
 
 
 
54
  PluginRegistry() {}
 
55
 
 
56
 
 
57
  st_plugin_int *find(const LEX_STRING *name);
 
58
 
 
59
  void add(st_plugin_int *plugin);
 
60
 
 
61
  std::vector<st_plugin_int *> get_list(bool active);
 
62
  static PluginRegistry& getPluginRegistry();
 
63
 
 
64
  void add(StorageEngine *engine);
 
65
  void add(InfoSchemaTable *schema_table);
 
66
  void add(Function_builder *udf);
 
67
  void add(Logging_handler *handler);
 
68
  void add(Error_message_handler *handler);
 
69
  void add(Authentication *auth);
 
70
  void add(QueryCache *qcache);
 
71
  void add(SchedulerFactory *scheduler);
 
72
  void add(ProtocolFactory *protocol);
 
73
  void add(drizzled::plugin::Replicator *repl);
 
74
 
 
75
  void remove(StorageEngine *engine);
 
76
  void remove(InfoSchemaTable *schema_table);
 
77
  void remove(Function_builder *udf);
 
78
  void remove(Logging_handler *handler);
 
79
  void remove(Error_message_handler *handler);
 
80
  void remove(Authentication *auth);
 
81
  void remove(QueryCache *qcache);
 
82
  void remove(SchedulerFactory *scheduler);
 
83
  void remove(ProtocolFactory *protocol);
 
84
  void remove(drizzled::plugin::Replicator *repl);
153
85
 
154
86
};
155
87
 
156
 
} /* namespace module */
157
 
} /* namespace drizzled */
158
 
#endif /* DRIZZLED_MODULE_REGISTRY_H */
 
88
#endif /* DRIZZLED_PLUGIN_REGISTRY_H */