~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/module/registry.h

  • Committer: Brian Aker
  • Date: 2010-12-17 00:08:06 UTC
  • mfrom: (2002.1.4 clean)
  • Revision ID: brian@tangent.org-20101217000806-fa6kmggjnhsl4q85
Rollup for field encapsulation, monty fix for bzrignore, and Andrew bug
fixes.

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