~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/module/registry.h

  • Committer: Brian Aker
  • Date: 2008-07-20 05:41:52 UTC
  • Revision ID: brian@tangent.org-20080720054152-5laf6plsb0o7h6ss
Documentation cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
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
 
 
20
 
#ifndef DRIZZLED_MODULE_REGISTRY_H
21
 
#define DRIZZLED_MODULE_REGISTRY_H
22
 
 
23
 
#include <string>
24
 
#include <vector>
25
 
#include <map>
26
 
#include <algorithm>
27
 
 
28
 
#include "drizzled/gettext.h"
29
 
#include "drizzled/unireg.h"
30
 
#include "drizzled/errmsg_print.h"
31
 
#include "drizzled/plugin/plugin.h"
32
 
 
33
 
namespace drizzled
34
 
{
35
 
 
36
 
namespace module
37
 
{
38
 
class Module;
39
 
class Library;
40
 
 
41
 
class Registry
42
 
{
43
 
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
 
 
48
 
  Registry()
49
 
   : module_map(),
50
 
     plugin_registry()
51
 
  { }
52
 
 
53
 
  Registry(const Registry&);
54
 
  Registry& operator=(const Registry&);
55
 
  ~Registry();
56
 
public:
57
 
 
58
 
  static Registry& singleton()
59
 
  {
60
 
    static Registry *registry= new Registry();
61
 
    return *registry;
62
 
  }
63
 
 
64
 
  void copy(plugin::Plugin::vector &arg);
65
 
 
66
 
  static void shutdown();
67
 
 
68
 
  Module *find(std::string name);
69
 
 
70
 
  void add(Module *module);
71
 
 
72
 
  void remove(Module *module);
73
 
 
74
 
  std::vector<Module *> getList(bool active);
75
 
 
76
 
  const std::map<std::string, plugin::Plugin *> &getPluginsMap() const
77
 
  {
78
 
    return plugin_registry;
79
 
  }
80
 
 
81
 
  const std::map<std::string, Module *> &getModulesMap() const
82
 
  {
83
 
    return module_map;
84
 
  }
85
 
 
86
 
  Library *addLibrary(const std::string &plugin_name, bool builtin= false);
87
 
  void removeLibrary(const std::string &plugin_name);
88
 
  Library *findLibrary(const std::string &plugin_name) const;
89
 
 
90
 
  void shutdownModules();
91
 
 
92
 
  template<class T>
93
 
  void add(T *plugin)
94
 
  {
95
 
    bool failed= false;
96
 
    std::string plugin_name(plugin->getName());
97
 
    std::transform(plugin_name.begin(), plugin_name.end(),
98
 
                   plugin_name.begin(), ::tolower);
99
 
    if (plugin_registry.find(plugin_name) != plugin_registry.end())
100
 
    {
101
 
      errmsg_printf(ERRMSG_LVL_ERROR,
102
 
                    _("Loading plugin %s failed: a plugin by that name already "
103
 
                      "exists.\n"), plugin->getName().c_str());
104
 
      failed= true;
105
 
    }
106
 
    if (T::addPlugin(plugin))
107
 
      failed= true;
108
 
    if (failed)
109
 
    {
110
 
      errmsg_printf(ERRMSG_LVL_ERROR,
111
 
                    _("Fatal error: Failed initializing %s plugin.\n"),
112
 
                    plugin->getName().c_str());
113
 
      unireg_abort(1);
114
 
    }
115
 
    plugin_registry.insert(std::pair<std::string, plugin::Plugin *>(plugin_name, plugin));
116
 
  }
117
 
 
118
 
  template<class T>
119
 
  void remove(T *plugin)
120
 
  {
121
 
    std::string plugin_name(plugin->getName());
122
 
    std::transform(plugin_name.begin(), plugin_name.end(),
123
 
                   plugin_name.begin(), ::tolower);
124
 
    T::removePlugin(plugin);
125
 
    plugin_registry.erase(plugin_name);
126
 
  }
127
 
 
128
 
 
129
 
};
130
 
 
131
 
} /* namespace module */
132
 
} /* namespace drizzled */
133
 
#endif /* DRIZZLED_MODULE_REGISTRY_H */