~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/registry.h

Added code necessary for building plugins dynamically.
Merged in changes from lifeless to allow autoreconf to work.
Touching plugin.ini files now triggers a rebuid - so config/autorun.sh is no
longer required to be run after touching those.
Removed the duplicate plugin names - also removed the issue that getting them
different would silently fail weirdly later.

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
 
#include "drizzled/name_map.h"
24
23
#include <string>
25
24
#include <vector>
26
25
#include <map>
 
26
#include <algorithm>
27
27
 
28
28
#include "drizzled/gettext.h"
29
29
#include "drizzled/unireg.h"
 
30
#include "drizzled/errmsg_print.h"
30
31
 
31
32
namespace drizzled
32
33
{
33
34
namespace plugin
34
35
{
35
 
class Handle;
 
36
class Module;
36
37
class Plugin;
37
38
 
38
39
class Registry
39
40
{
40
41
private:
41
 
  std::map<std::string, Handle *> handle_map;
42
 
  NameMap<const Plugin *> plugin_registry;
 
42
  std::map<std::string, Module *> module_map;
 
43
  std::map<std::string, const Plugin *> plugin_registry;
43
44
 
44
 
  Handle *current_handle;
 
45
  Module *current_module;
45
46
 
46
47
  Registry()
47
 
   : handle_map(),
 
48
   : module_map(),
48
49
     plugin_registry(),
49
 
     current_handle(NULL)
 
50
     current_module(NULL)
50
51
  { }
51
52
 
52
53
  Registry(const Registry&);
65
66
    delete &registry;
66
67
  }
67
68
 
68
 
  Handle *find(const LEX_STRING *name);
69
 
 
70
 
  void add(Handle *handle);
71
 
 
72
 
  void setCurrentHandle(Handle *plugin)
73
 
  {
74
 
    current_handle= plugin;
75
 
  }
76
 
 
77
 
  void clearCurrentHandle()
78
 
  {
79
 
    current_handle= NULL;
80
 
  }
81
 
 
82
 
  std::vector<Handle *> getList(bool active);
 
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
  }
83
89
 
84
90
  template<class T>
85
91
  void add(T *plugin)
86
92
  {
87
 
    plugin->setHandle(current_handle);
 
93
    plugin->setModule(current_module);
88
94
    bool failed= false;
89
 
    if (plugin_registry.add(plugin))
 
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());
90
103
      failed= true;
 
104
    }
91
105
    if (T::addPlugin(plugin))
92
106
      failed= true;
93
107
    if (failed)
94
108
    {
95
 
      /* Can't use errmsg_printf here because we might be initializing the
96
 
       * error_message plugin.
97
 
       */
98
 
      fprintf(stderr,
99
 
              _("Fatal error: Failed initializing %s plugin."),
100
 
              plugin->getName().c_str());
 
109
      errmsg_printf(ERRMSG_LVL_ERROR,
 
110
                    _("Fatal error: Failed initializing %s plugin."),
 
111
                    plugin->getName().c_str());
101
112
      unireg_abort(1);
102
113
    }
 
114
    plugin_registry.insert(std::pair<std::string, const Plugin *>(plugin_name, plugin));
103
115
  }
104
116
 
105
117
  template<class T>
106
118
  void remove(T *plugin)
107
119
  {
 
120
    std::string plugin_name(plugin->getName());
 
121
    std::transform(plugin_name.begin(), plugin_name.end(),
 
122
                   plugin_name.begin(), ::tolower);
108
123
    T::removePlugin(plugin);
109
 
    plugin_registry.remove(plugin);
 
124
    plugin_registry.erase(plugin_name);
110
125
  }
111
126
 
112
127
};