~drizzle-developers/drizzle/elliott-release

« back to all changes in this revision

Viewing changes to drizzled/module/registry.cc

  • Committer: Patrick Crews
  • Date: 2011-02-01 20:33:06 UTC
  • mfrom: (1845.2.288 drizzle)
  • Revision ID: gleebix@gmail.com-20110201203306-mwq2rk0it81tlwxh
Merged Trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
#include "drizzled/module/registry.h"
27
27
#include "drizzled/module/library.h"
 
28
#include "drizzled/module/graph.h"
 
29
#include "drizzled/module/vertex_handle.h"
28
30
 
29
31
#include "drizzled/plugin.h"
30
32
#include "drizzled/show.h"
31
33
#include "drizzled/cursor.h"
 
34
#include "drizzled/abort_exception.h"
32
35
 
33
36
#include <boost/bind.hpp>
34
37
 
37
40
namespace drizzled
38
41
{
39
42
 
 
43
module::Registry::Registry() :
 
44
  module_registry_(),
 
45
  depend_graph_(new module::Graph()),
 
46
  plugin_registry(),
 
47
  deps_built_(false)
 
48
{ }
 
49
 
40
50
 
41
51
module::Registry::~Registry()
42
52
{
96
106
  map_iter= module_registry_.find(name);
97
107
  if (map_iter != module_registry_.end())
98
108
    return (*map_iter).second;
99
 
  return(0);
 
109
  return NULL;
100
110
}
101
111
 
102
112
void module::Registry::add(module::Module *handle)
106
116
            add_str.begin(), ::tolower);
107
117
 
108
118
  module_registry_[add_str]= handle;
 
119
 
 
120
  Vertex vertex_info(add_str, handle);
 
121
  VertexDesc handle_vertex= boost::add_vertex(depend_graph_->getGraph());
 
122
  depend_graph_->properties(handle_vertex)= vertex_info;
 
123
 
 
124
  handle->setVertexHandle(new VertexHandle(handle_vertex));
 
125
 
109
126
}
110
127
 
111
128
void module::Registry::remove(module::Module *handle)
128
145
  assert(arg.size() == plugin_registry.size());
129
146
}
130
147
 
131
 
vector<module::Module *> module::Registry::getList(bool active)
132
 
{
133
 
  module::Module *plugin= NULL;
 
148
void module::Registry::buildDeps()
 
149
{
 
150
  ModuleMap::iterator map_iter= module_registry_.begin();
 
151
  while (map_iter != module_registry_.end())
 
152
  {
 
153
    Module *handle= (*map_iter).second;
 
154
    Module::Depends::const_iterator handle_deps= handle->getDepends().begin();
 
155
    while (handle_deps != handle->getDepends().end())
 
156
    {
 
157
      std::string dep_str((*handle_deps));
 
158
      transform(dep_str.begin(), dep_str.end(),
 
159
                dep_str.begin(), ::tolower);
 
160
 
 
161
      bool found_dep= false;
 
162
      vertex_iter it= boost::vertices(depend_graph_->getGraph()).first;
 
163
      while (it != vertices(depend_graph_->getGraph()).second)
 
164
      {
 
165
        if (depend_graph_->properties(*it).getName() == dep_str)
 
166
        {
 
167
          found_dep= true;
 
168
          add_edge(handle->getVertexHandle()->getVertexDesc(), *it, depend_graph_->getGraph());
 
169
          break;
 
170
        }
 
171
        ++it;
 
172
      }
 
173
      if (not found_dep)
 
174
      {
 
175
        errmsg_printf(ERRMSG_LVL_ERROR,
 
176
                      _("Couldn't process plugin module dependencies. "
 
177
                        "%s depends on %s but %s is not to be loaded.\n"),
 
178
                      handle->getName().c_str(),
 
179
                      dep_str.c_str(), dep_str.c_str());
 
180
        DRIZZLE_ABORT;
 
181
      }
 
182
 
 
183
      ++handle_deps;
 
184
    }
 
185
    ++map_iter;
 
186
  }
 
187
  deps_built_= true;
 
188
}
 
189
 
 
190
module::Registry::ModuleList module::Registry::getList()
 
191
{
 
192
  if (not deps_built_)
 
193
  {
 
194
    buildDeps();
 
195
  }
134
196
 
135
197
  std::vector<module::Module *> plugins;
136
 
  plugins.reserve(module_registry_.size());
137
 
 
138
 
  ModuleMap::iterator map_iter;
139
 
  for (map_iter= module_registry_.begin();
140
 
       map_iter != module_registry_.end();
141
 
       map_iter++)
 
198
 
 
199
  VertexList vertex_list;
 
200
 
 
201
  boost::topological_sort(depend_graph_->getGraph(), std::back_inserter(vertex_list));
 
202
 
 
203
  for (VertexList::iterator i = vertex_list.begin();
 
204
       i != vertex_list.end(); ++i)
142
205
  {
143
 
    plugin= (*map_iter).second;
144
 
    if (active)
145
 
      plugins.push_back(plugin);
146
 
    else if (plugin->isInited)
147
 
      plugins.push_back(plugin);
 
206
    Module *mod_ptr= depend_graph_->properties(*i).getModule();
 
207
    if (mod_ptr != NULL)
 
208
    {
 
209
      plugins.push_back(mod_ptr);
 
210
    }  
148
211
  }
149
212
 
150
213
  return plugins;