~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/module/registry.h

Use List::begin()

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
 
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
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
24
24
#include <vector>
25
25
#include <map>
26
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"
 
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
 
32
36
 
33
37
namespace drizzled
34
38
{
37
41
{
38
42
class Module;
39
43
class Library;
 
44
class Graph;
 
45
 
40
46
 
41
47
class Registry
42
48
{
 
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;
43
54
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
 
 
 
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();
53
64
  Registry(const Registry&);
54
65
  Registry& operator=(const Registry&);
55
66
  ~Registry();
 
67
 
 
68
  void buildDeps();
56
69
public:
57
70
 
58
71
  static Registry& singleton()
71
84
 
72
85
  void remove(Module *module);
73
86
 
74
 
  std::vector<Module *> getList(bool active);
 
87
  std::vector<Module *> getList();
75
88
 
76
 
  const std::map<std::string, plugin::Plugin *> &getPluginsMap() const
 
89
  const plugin::Plugin::map &getPluginsMap() const
77
90
  {
78
91
    return plugin_registry;
79
92
  }
80
93
 
81
 
  const std::map<std::string, Module *> &getModulesMap() const
 
94
  const ModuleMap &getModulesMap() const
82
95
  {
83
 
    return module_map;
 
96
    return module_registry_;
84
97
  }
85
98
 
86
99
  Library *addLibrary(const std::string &plugin_name, bool builtin= false);
93
106
  void add(T *plugin)
94
107
  {
95
108
    bool failed= false;
 
109
    std::string plugin_type(plugin->getTypeName());
 
110
    std::transform(plugin_type.begin(), plugin_type.end(),
 
111
                   plugin_type.begin(), ::tolower);
96
112
    std::string plugin_name(plugin->getName());
97
113
    std::transform(plugin_name.begin(), plugin_name.end(),
98
114
                   plugin_name.begin(), ::tolower);
99
 
    if (plugin_registry.find(plugin_name) != plugin_registry.end())
 
115
    if (plugin_registry.find(std::make_pair(plugin_type, plugin_name)) != plugin_registry.end())
100
116
    {
101
 
      errmsg_printf(ERRMSG_LVL_ERROR,
102
 
                    _("Loading plugin %s failed: a plugin by that name already "
103
 
                      "exists.\n"), plugin->getName().c_str());
 
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());
104
122
      failed= true;
105
123
    }
106
124
    if (T::addPlugin(plugin))
 
125
    {
107
126
      failed= true;
 
127
    }
 
128
 
108
129
    if (failed)
109
130
    {
110
 
      errmsg_printf(ERRMSG_LVL_ERROR,
111
 
                    _("Fatal error: Failed initializing %s plugin.\n"),
 
131
      errmsg_printf(error::ERROR,
 
132
                    _("Fatal error: Failed initializing %s::%s plugin.\n"),
 
133
                    plugin->getTypeName().c_str(),
112
134
                    plugin->getName().c_str());
113
135
      unireg_abort(1);
114
136
    }
115
 
    plugin_registry.insert(std::pair<std::string, plugin::Plugin *>(plugin_name, plugin));
 
137
    plugin_registry.insert(std::make_pair(std::make_pair(plugin_type, plugin_name), plugin));
116
138
  }
117
139
 
118
140
  template<class T>
119
141
  void remove(T *plugin)
120
142
  {
 
143
    std::string plugin_type(plugin->getTypeName());
 
144
    std::transform(plugin_type.begin(), plugin_type.end(),
 
145
                   plugin_type.begin(), ::tolower);
121
146
    std::string plugin_name(plugin->getName());
122
147
    std::transform(plugin_name.begin(), plugin_name.end(),
123
148
                   plugin_name.begin(), ::tolower);
124
149
    T::removePlugin(plugin);
125
 
    plugin_registry.erase(plugin_name);
 
150
    plugin_registry.erase(std::make_pair(plugin_type, plugin_name));
126
151
  }
127
152
 
128
153