~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin_registry.h

  • Committer: Monty Taylor
  • Date: 2009-04-20 14:42:34 UTC
  • mto: (997.2.5 mordred)
  • mto: This revision was merged to the branch mainline in revision 1003.
  • Revision ID: mordred@inaugust.com-20090420144234-4k1x60fiag2l1y0n
Ported InnoDB to register_plugins.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#ifndef DRIZZLED_PLUGIN_REGISTRY_H
21
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
 
 
28
 
#include "drizzled/gettext.h"
29
 
#include "drizzled/unireg.h"
30
 
#include "drizzled/errmsg_print.h"
31
 
 
 
27
 
 
28
struct st_plugin_int;
 
29
class StorageEngine;
 
30
struct 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;
32
38
namespace drizzled
33
39
{
34
40
namespace plugin
35
41
{
36
 
class Module;
37
 
class Plugin;
 
42
class Replicator;
 
43
}
 
44
}
38
45
 
39
 
class Registry
 
46
class PluginRegistry
40
47
{
41
48
private:
42
 
  std::map<std::string, Module *> module_map;
43
 
  std::map<std::string, const Plugin *> plugin_registry;
44
 
 
45
 
  Module *current_module;
46
 
 
47
 
  Registry()
48
 
   : module_map(),
49
 
     plugin_registry(),
50
 
     current_module(NULL)
51
 
  { }
52
 
 
53
 
  Registry(const Registry&);
54
 
  Registry& operator=(const Registry&);
 
49
  std::map<std::string, st_plugin_int *>
 
50
    plugin_map;
 
51
 
 
52
  PluginRegistry(const PluginRegistry&);
55
53
public:
56
 
 
57
 
  static plugin::Registry& singleton()
58
 
  {
59
 
    static plugin::Registry *registry= new plugin::Registry();
60
 
    return *registry;
61
 
  }
62
 
 
63
 
  static void shutdown()
64
 
  {
65
 
    plugin::Registry& registry= singleton();
66
 
    delete &registry;
67
 
  }
68
 
 
69
 
  Module *find(const LEX_STRING *name);
70
 
 
71
 
  void add(Module *module);
72
 
 
73
 
  void setCurrentModule(Module *module)
74
 
  {
75
 
    current_module= module;
76
 
  }
77
 
 
78
 
  void clearCurrentModule()
79
 
  {
80
 
    current_module= NULL;
81
 
  }
82
 
 
83
 
  std::vector<Module *> getList(bool active);
84
 
 
85
 
  const std::map<std::string, const Plugin *> &getPluginsMap() const
86
 
  {
87
 
    return plugin_registry;
88
 
  }
89
 
 
90
 
  template<class T>
91
 
  void add(T *plugin)
92
 
  {
93
 
    plugin->setModule(current_module);
94
 
    bool failed= false;
95
 
    std::string plugin_name(plugin->getName());
96
 
    std::transform(plugin_name.begin(), plugin_name.end(),
97
 
                   plugin_name.begin(), ::tolower);
98
 
    if (plugin_registry.find(plugin_name) != plugin_registry.end())
99
 
    {
100
 
      errmsg_printf(ERRMSG_LVL_ERROR,
101
 
                    _("Loading plugin %s failed: a plugin by that name already "
102
 
                      "exists."), plugin->getName().c_str());
103
 
      failed= true;
104
 
    }
105
 
    if (T::addPlugin(plugin))
106
 
      failed= true;
107
 
    if (failed)
108
 
    {
109
 
      errmsg_printf(ERRMSG_LVL_ERROR,
110
 
                    _("Fatal error: Failed initializing %s plugin."),
111
 
                    plugin->getName().c_str());
112
 
      unireg_abort(1);
113
 
    }
114
 
    plugin_registry.insert(std::pair<std::string, const Plugin *>(plugin_name, plugin));
115
 
  }
116
 
 
117
 
  template<class T>
118
 
  void remove(T *plugin)
119
 
  {
120
 
    std::string plugin_name(plugin->getName());
121
 
    std::transform(plugin_name.begin(), plugin_name.end(),
122
 
                   plugin_name.begin(), ::tolower);
123
 
    T::removePlugin(plugin);
124
 
    plugin_registry.erase(plugin_name);
125
 
  }
 
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);
126
85
 
127
86
};
128
87
 
129
 
} /* end namespace plugin */
130
 
} /* end namespace drizzled */
131
88
#endif /* DRIZZLED_PLUGIN_REGISTRY_H */