~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/module/registry.h

  • Committer: kalebral at gmail
  • Date: 2010-12-04 04:58:08 UTC
  • mto: (1971.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1972.
  • Revision ID: kalebral@gmail.com-20101204045808-acto22oxfg43m02e
a few more updates of files that did not have license or had incorrect license structure

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