~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/module/registry.h

  • Committer: Stewart Smith
  • Date: 2011-01-21 01:09:12 UTC
  • mfrom: (2099 staging)
  • mto: (2099.1.3 build)
  • mto: This revision was merged to the branch mainline in revision 2100.
  • Revision ID: stewart@flamingspork.com-20110121010912-x5ogi8rm08nortxp
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
 
41
41
class Registry
42
42
{
 
43
public:
 
44
  typedef std::map<std::string, Library *> LibraryMap;
 
45
  typedef std::map<std::string, Module *> ModuleMap;
43
46
private:
44
 
  std::map<std::string, Library *> library_map;
45
 
  std::map<std::string, Module *> module_map;
46
 
  std::map<std::string, plugin::Plugin *> plugin_registry;
 
47
  LibraryMap library_registry_;
 
48
  ModuleMap module_registry_;
 
49
  
 
50
  plugin::Plugin::map plugin_registry;
47
51
 
48
52
  Registry()
49
 
   : module_map(),
 
53
   : module_registry_(),
50
54
     plugin_registry()
51
55
  { }
52
56
 
73
77
 
74
78
  std::vector<Module *> getList(bool active);
75
79
 
76
 
  const std::map<std::string, plugin::Plugin *> &getPluginsMap() const
 
80
  const plugin::Plugin::map &getPluginsMap() const
77
81
  {
78
82
    return plugin_registry;
79
83
  }
80
84
 
81
 
  const std::map<std::string, Module *> &getModulesMap() const
 
85
  const ModuleMap &getModulesMap() const
82
86
  {
83
 
    return module_map;
 
87
    return module_registry_;
84
88
  }
85
89
 
86
90
  Library *addLibrary(const std::string &plugin_name, bool builtin= false);
93
97
  void add(T *plugin)
94
98
  {
95
99
    bool failed= false;
 
100
    std::string plugin_type(plugin->getTypeName());
 
101
    std::transform(plugin_type.begin(), plugin_type.end(),
 
102
                   plugin_type.begin(), ::tolower);
96
103
    std::string plugin_name(plugin->getName());
97
104
    std::transform(plugin_name.begin(), plugin_name.end(),
98
105
                   plugin_name.begin(), ::tolower);
99
 
    if (plugin_registry.find(plugin_name) != plugin_registry.end())
 
106
    if (plugin_registry.find(std::make_pair(plugin_type, plugin_name)) != plugin_registry.end())
100
107
    {
101
108
      errmsg_printf(ERRMSG_LVL_ERROR,
102
 
                    _("Loading plugin %s failed: a plugin by that name already "
103
 
                      "exists.\n"), plugin->getName().c_str());
 
109
                    _("Loading plugin %s failed: a %s plugin by that name "
 
110
                      "already exists.\n"),
 
111
                    plugin->getTypeName().c_str(),
 
112
                    plugin->getName().c_str());
104
113
      failed= true;
105
114
    }
106
115
    if (T::addPlugin(plugin))
 
116
    {
107
117
      failed= true;
 
118
    }
 
119
 
108
120
    if (failed)
109
121
    {
110
122
      errmsg_printf(ERRMSG_LVL_ERROR,
111
 
                    _("Fatal error: Failed initializing %s plugin.\n"),
 
123
                    _("Fatal error: Failed initializing %s::%s plugin.\n"),
 
124
                    plugin->getTypeName().c_str(),
112
125
                    plugin->getName().c_str());
113
126
      unireg_abort(1);
114
127
    }
115
 
    plugin_registry.insert(std::pair<std::string, plugin::Plugin *>(plugin_name, plugin));
 
128
    plugin_registry.insert(std::make_pair(std::make_pair(plugin_type, plugin_name), plugin));
116
129
  }
117
130
 
118
131
  template<class T>
119
132
  void remove(T *plugin)
120
133
  {
 
134
    std::string plugin_type(plugin->getTypeName());
 
135
    std::transform(plugin_type.begin(), plugin_type.end(),
 
136
                   plugin_type.begin(), ::tolower);
121
137
    std::string plugin_name(plugin->getName());
122
138
    std::transform(plugin_name.begin(), plugin_name.end(),
123
139
                   plugin_name.begin(), ::tolower);
124
140
    T::removePlugin(plugin);
125
 
    plugin_registry.erase(plugin_name);
 
141
    plugin_registry.erase(std::make_pair(plugin_type, plugin_name));
126
142
  }
127
143
 
128
144