~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/registry.h

  • Committer: Stewart Smith
  • Date: 2009-10-08 12:39:27 UTC
  • mto: This revision was merged to the branch mainline in revision 1179.
  • Revision ID: stewart@flamingspork.com-20091008123927-qpf9hog04w4xc5aj
make directory_file_name() static to mysys/my_lib.cc

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <string>
24
24
#include <vector>
25
25
#include <map>
26
 
#include <algorithm>
27
26
 
28
27
#include "drizzled/gettext.h"
29
28
#include "drizzled/unireg.h"
30
 
#include "drizzled/errmsg_print.h"
31
29
 
32
30
namespace drizzled
33
31
{
34
32
namespace plugin
35
33
{
36
 
class Module;
37
 
class Plugin;
38
 
class Library;
 
34
class Handle;
39
35
 
40
36
class Registry
41
37
{
42
38
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
 
 
 
39
  std::map<std::string, Handle *>
 
40
    plugin_map;
 
41
 
 
42
  Registry() {}
52
43
  Registry(const Registry&);
53
 
  Registry& operator=(const Registry&);
54
 
  ~Registry();
55
44
public:
56
45
 
57
46
  static plugin::Registry& singleton()
58
47
  {
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;
 
48
    static plugin::Registry registry;
 
49
    return registry;
 
50
  }
 
51
 
 
52
  Handle *find(const LEX_STRING *name);
 
53
 
 
54
  void add(Handle *plugin);
 
55
 
 
56
  std::vector<Handle *> getList(bool active);
85
57
 
86
58
  template<class T>
87
59
  void add(T *plugin)
88
60
  {
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;
 
61
    bool failed= T::addPlugin(plugin);
102
62
    if (failed)
103
63
    {
104
 
      errmsg_printf(ERRMSG_LVL_ERROR,
105
 
                    _("Fatal error: Failed initializing %s plugin.\n"),
106
 
                    plugin->getName().c_str());
 
64
      /* Can't use errmsg_printf here because we might be initializing the
 
65
       * error_message plugin.
 
66
       */
 
67
      /**
 
68
       * @TODO
 
69
       * Once plugin-base-class is merged, we'll add in this statment
 
70
       * fprintf(stderr,
 
71
       *       _("Fatal error: Failed initializing %s plugin."),
 
72
       *       plugin->getName().c_str());
 
73
       */
107
74
      unireg_abort(1);
108
75
    }
109
 
    plugin_registry.insert(std::pair<std::string, Plugin *>(plugin_name, plugin));
110
76
  }
111
77
 
112
78
  template<class T>
113
79
  void remove(T *plugin)
114
80
  {
115
 
    std::string plugin_name(plugin->getName());
116
 
    std::transform(plugin_name.begin(), plugin_name.end(),
117
 
                   plugin_name.begin(), ::tolower);
118
81
    T::removePlugin(plugin);
119
 
    plugin_registry.erase(plugin_name);
120
82
  }
121
83
 
122
 
 
123
84
};
124
85
 
125
86
} /* end namespace plugin */