~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/registry.h

  • Committer: Brian Aker
  • Date: 2009-01-24 09:43:35 UTC
  • Revision ID: brian@gir-3.local-20090124094335-6qdtvc35gl5fvivz
Adding in an example singe thread scheduler

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_PLUGIN_REGISTRY_H
21
 
#define DRIZZLED_PLUGIN_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
 
 
32
 
namespace drizzled
33
 
{
34
 
namespace plugin
35
 
{
36
 
class Module;
37
 
class Plugin;
38
 
class Library;
39
 
 
40
 
class Registry
41
 
{
42
 
private:
43
 
  std::map<std::string, Library *> library_map;
44
 
  std::map<std::string, Module *> module_map;
45
 
  std::map<std::string, Plugin *> plugin_registry;
46
 
 
47
 
  Registry()
48
 
   : module_map(),
49
 
     plugin_registry()
50
 
  { }
51
 
 
52
 
  Registry(const Registry&);
53
 
  Registry& operator=(const Registry&);
54
 
  ~Registry();
55
 
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
 
  Module *find(std::string name);
66
 
 
67
 
  void add(Module *module);
68
 
 
69
 
 
70
 
  std::vector<Module *> getList(bool active);
71
 
 
72
 
  const std::map<std::string, Plugin *> &getPluginsMap() const
73
 
  {
74
 
    return plugin_registry;
75
 
  }
76
 
 
77
 
  const std::map<std::string, Module *> &getModulesMap() const
78
 
  {
79
 
    return module_map;
80
 
  }
81
 
 
82
 
  Library *addLibrary(const std::string &plugin_name);
83
 
  void removeLibrary(const std::string &plugin_name);
84
 
  Library *findLibrary(const std::string &plugin_name) const;
85
 
 
86
 
  template<class T>
87
 
  void add(T *plugin)
88
 
  {
89
 
    bool failed= false;
90
 
    std::string plugin_name(plugin->getName());
91
 
    std::transform(plugin_name.begin(), plugin_name.end(),
92
 
                   plugin_name.begin(), ::tolower);
93
 
    if (plugin_registry.find(plugin_name) != plugin_registry.end())
94
 
    {
95
 
      errmsg_printf(ERRMSG_LVL_ERROR,
96
 
                    _("Loading plugin %s failed: a plugin by that name already "
97
 
                      "exists.\n"), plugin->getName().c_str());
98
 
      failed= true;
99
 
    }
100
 
    if (T::addPlugin(plugin))
101
 
      failed= true;
102
 
    if (failed)
103
 
    {
104
 
      errmsg_printf(ERRMSG_LVL_ERROR,
105
 
                    _("Fatal error: Failed initializing %s plugin.\n"),
106
 
                    plugin->getName().c_str());
107
 
      unireg_abort(1);
108
 
    }
109
 
    plugin_registry.insert(std::pair<std::string, Plugin *>(plugin_name, plugin));
110
 
  }
111
 
 
112
 
  template<class T>
113
 
  void remove(T *plugin)
114
 
  {
115
 
    std::string plugin_name(plugin->getName());
116
 
    std::transform(plugin_name.begin(), plugin_name.end(),
117
 
                   plugin_name.begin(), ::tolower);
118
 
    T::removePlugin(plugin);
119
 
    plugin_registry.erase(plugin_name);
120
 
  }
121
 
 
122
 
 
123
 
};
124
 
 
125
 
} /* end namespace plugin */
126
 
} /* end namespace drizzled */
127
 
#endif /* DRIZZLED_PLUGIN_REGISTRY_H */