~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/registry.h

  • Committer: Djellel E. Difallah
  • Date: 2010-03-27 10:10:49 UTC
  • mto: This revision was merged to the branch mainline in revision 1429.
  • Revision ID: ded@ubuntu-20100327101049-oo3arvatjoyku124
merge my_decimal and decimal

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#ifndef DRIZZLED_MODULE_REGISTRY_H
21
 
#define DRIZZLED_MODULE_REGISTRY_H
 
20
#ifndef DRIZZLED_PLUGIN_REGISTRY_H
 
21
#define DRIZZLED_PLUGIN_REGISTRY_H
22
22
 
23
23
#include <string>
24
24
#include <vector>
25
25
#include <map>
26
26
#include <algorithm>
27
 
#include <iostream>
28
 
 
29
 
#include <boost/scoped_ptr.hpp>
30
 
 
31
 
#include <drizzled/gettext.h>
32
 
#include <drizzled/unireg.h>
33
 
#include <drizzled/errmsg_print.h>
34
 
#include <drizzled/plugin/plugin.h>
35
 
 
 
27
 
 
28
#include "drizzled/gettext.h"
 
29
#include "drizzled/unireg.h"
 
30
#include "drizzled/errmsg_print.h"
36
31
 
37
32
namespace drizzled
38
33
{
39
 
 
40
 
namespace module
 
34
namespace plugin
41
35
{
42
36
class Module;
 
37
class Plugin;
43
38
class Library;
44
 
class Graph;
45
 
 
46
39
 
47
40
class Registry
48
41
{
49
 
public:
50
 
 
51
 
  typedef std::map<std::string, Library *> LibraryMap;
52
 
  typedef std::map<std::string, Module *> ModuleMap;
53
 
  typedef std::vector<Module *> ModuleList;
54
42
private:
55
 
  LibraryMap library_registry_;
56
 
  ModuleMap module_registry_;
57
 
  boost::scoped_ptr<Graph> depend_graph_; 
58
 
  
59
 
  plugin::Plugin::map plugin_registry;
60
 
 
61
 
  bool deps_built_;
62
 
 
63
 
  Registry();
 
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
 
64
52
  Registry(const Registry&);
65
53
  Registry& operator=(const Registry&);
66
54
  ~Registry();
67
 
 
68
 
  void buildDeps();
69
55
public:
70
56
 
71
 
  static Registry& singleton()
 
57
  static plugin::Registry& singleton()
72
58
  {
73
 
    static Registry *registry= new Registry();
 
59
    static plugin::Registry *registry= new plugin::Registry();
74
60
    return *registry;
75
61
  }
76
62
 
77
 
  void copy(plugin::Plugin::vector &arg);
78
 
 
79
63
  static void shutdown();
80
64
 
81
65
  Module *find(std::string name);
82
66
 
83
67
  void add(Module *module);
84
68
 
85
 
  void remove(Module *module);
86
 
 
87
 
  std::vector<Module *> getList();
88
 
 
89
 
  const plugin::Plugin::map &getPluginsMap() const
 
69
 
 
70
  std::vector<Module *> getList(bool active);
 
71
 
 
72
  const std::map<std::string, Plugin *> &getPluginsMap() const
90
73
  {
91
74
    return plugin_registry;
92
75
  }
93
76
 
94
 
  const ModuleMap &getModulesMap() const
 
77
  const std::map<std::string, Module *> &getModulesMap() const
95
78
  {
96
 
    return module_registry_;
 
79
    return module_map;
97
80
  }
98
81
 
99
 
  Library *addLibrary(const std::string &plugin_name, bool builtin= false);
 
82
  Library *addLibrary(const std::string &plugin_name);
100
83
  void removeLibrary(const std::string &plugin_name);
101
84
  Library *findLibrary(const std::string &plugin_name) const;
102
85
 
103
 
  void shutdownModules();
104
 
 
105
86
  template<class T>
106
87
  void add(T *plugin)
107
88
  {
108
89
    bool failed= false;
109
 
    std::string plugin_type(plugin->getTypeName());
110
 
    std::transform(plugin_type.begin(), plugin_type.end(),
111
 
                   plugin_type.begin(), ::tolower);
112
90
    std::string plugin_name(plugin->getName());
113
91
    std::transform(plugin_name.begin(), plugin_name.end(),
114
92
                   plugin_name.begin(), ::tolower);
115
 
    if (plugin_registry.find(std::make_pair(plugin_type, plugin_name)) != plugin_registry.end())
 
93
    if (plugin_registry.find(plugin_name) != plugin_registry.end())
116
94
    {
117
 
      errmsg_printf(error::ERROR,
118
 
                    _("Loading plugin %s failed: a %s plugin by that name "
119
 
                      "already exists.\n"),
120
 
                    plugin->getTypeName().c_str(),
121
 
                    plugin->getName().c_str());
 
95
      errmsg_printf(ERRMSG_LVL_ERROR,
 
96
                    _("Loading plugin %s failed: a plugin by that name already "
 
97
                      "exists.\n"), plugin->getName().c_str());
122
98
      failed= true;
123
99
    }
124
100
    if (T::addPlugin(plugin))
125
 
    {
126
101
      failed= true;
127
 
    }
128
 
 
129
102
    if (failed)
130
103
    {
131
 
      errmsg_printf(error::ERROR,
132
 
                    _("Fatal error: Failed initializing %s::%s plugin.\n"),
133
 
                    plugin->getTypeName().c_str(),
 
104
      errmsg_printf(ERRMSG_LVL_ERROR,
 
105
                    _("Fatal error: Failed initializing %s plugin.\n"),
134
106
                    plugin->getName().c_str());
135
107
      unireg_abort(1);
136
108
    }
137
 
    plugin_registry.insert(std::make_pair(std::make_pair(plugin_type, plugin_name), plugin));
 
109
    plugin_registry.insert(std::pair<std::string, Plugin *>(plugin_name, plugin));
138
110
  }
139
111
 
140
112
  template<class T>
141
113
  void remove(T *plugin)
142
114
  {
143
 
    std::string plugin_type(plugin->getTypeName());
144
 
    std::transform(plugin_type.begin(), plugin_type.end(),
145
 
                   plugin_type.begin(), ::tolower);
146
115
    std::string plugin_name(plugin->getName());
147
116
    std::transform(plugin_name.begin(), plugin_name.end(),
148
117
                   plugin_name.begin(), ::tolower);
149
118
    T::removePlugin(plugin);
150
 
    plugin_registry.erase(std::make_pair(plugin_type, plugin_name));
 
119
    plugin_registry.erase(plugin_name);
151
120
  }
152
121
 
153
122
 
154
123
};
155
124
 
156
 
} /* namespace module */
157
 
} /* namespace drizzled */
158
 
#endif /* DRIZZLED_MODULE_REGISTRY_H */
 
125
} /* end namespace plugin */
 
126
} /* end namespace drizzled */
 
127
#endif /* DRIZZLED_PLUGIN_REGISTRY_H */