~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/module/registry.cc

  • Committer: Monty Taylor
  • Date: 2011-01-18 20:50:12 UTC
  • mto: (2114.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 2115.
  • Revision ID: mordred@inaugust.com-20110118205012-34bt3viv2rvefsx4
Actually properly process module dependencies. w00t.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include "drizzled/plugin.h"
30
30
#include "drizzled/show.h"
31
31
#include "drizzled/cursor.h"
 
32
#include "drizzled/abort_exception.h"
32
33
 
33
34
#include <boost/bind.hpp>
34
35
 
107
108
 
108
109
  module_registry_[add_str]= handle;
109
110
 
110
 
  VertexDesc handle_vertex;
111
111
  Vertex vertex_info(add_str, handle);
112
 
 
113
 
  /* It's possible we could have added a vertex without a module attached
114
 
     as part of adding dependency edges */
115
 
  bool found_vertex= false;
116
 
  vertex_iter vertexes= boost::vertices(depend_graph_).first;
117
 
  while (vertexes != vertices(depend_graph_).second)
118
 
  {
119
 
    if (properties(*vertexes).getName() == add_str)
120
 
    {
121
 
      found_vertex= true;
122
 
      break;
123
 
    }
124
 
    ++vertexes;
125
 
  }
126
 
  if (found_vertex)
127
 
  {
128
 
    handle_vertex= *vertexes;
129
 
  }
130
 
  else
131
 
  {
132
 
    handle_vertex= boost::add_vertex(depend_graph_);
133
 
  }
 
112
  VertexDesc handle_vertex= boost::add_vertex(depend_graph_);
134
113
  properties(handle_vertex)= vertex_info;
135
114
 
136
 
 
137
 
  Module::Depends::const_iterator handle_deps= handle->getDepends().begin();
138
 
  while (handle_deps != handle->getDepends().end())
139
 
  {
140
 
    std::string dep_str((*handle_deps));
141
 
    transform(dep_str.begin(), dep_str.end(),
142
 
              dep_str.begin(), ::tolower);
143
 
 
144
 
    bool found_dep= false;
145
 
    vertex_iter it= boost::vertices(depend_graph_).first;
146
 
    while (it != vertices(depend_graph_).second)
147
 
    {
148
 
      if (properties(*it).getName() == dep_str)
149
 
      {
150
 
        found_dep= true;
151
 
        add_edge(handle_vertex, *it, depend_graph_);
152
 
        break;
153
 
      }
154
 
      ++it;
155
 
    }
156
 
    if (not found_dep)
157
 
    {
158
 
      Vertex dep_vertex_info(dep_str);
159
 
      VertexDesc dep_vertex= boost::add_vertex(depend_graph_);
160
 
      properties(dep_vertex)= dep_vertex_info;
161
 
    }
162
 
 
163
 
    ++handle_deps;
164
 
  }
 
115
  handle->setVertexDesc(handle_vertex);
165
116
 
166
117
}
167
118
 
185
136
  assert(arg.size() == plugin_registry.size());
186
137
}
187
138
 
 
139
void module::Registry::buildDeps()
 
140
{
 
141
  ModuleMap::iterator map_iter= module_registry_.begin();
 
142
  while (map_iter != module_registry_.end())
 
143
  {
 
144
    Module *handle= (*map_iter).second;
 
145
    Module::Depends::const_iterator handle_deps= handle->getDepends().begin();
 
146
    while (handle_deps != handle->getDepends().end())
 
147
    {
 
148
      std::string dep_str((*handle_deps));
 
149
      transform(dep_str.begin(), dep_str.end(),
 
150
                dep_str.begin(), ::tolower);
 
151
 
 
152
      bool found_dep= false;
 
153
      vertex_iter it= boost::vertices(depend_graph_).first;
 
154
      while (it != vertices(depend_graph_).second)
 
155
      {
 
156
        if (properties(*it).getName() == dep_str)
 
157
        {
 
158
          found_dep= true;
 
159
          add_edge(handle->getVertexDesc(), *it, depend_graph_);
 
160
          break;
 
161
        }
 
162
        ++it;
 
163
      }
 
164
      if (not found_dep)
 
165
      {
 
166
        errmsg_printf(ERRMSG_LVL_ERROR,
 
167
                      _("Couldn't process plugin module dependencies. "
 
168
                        "%s depends on %s but %s is not to be loaded.\n"),
 
169
                      handle->getName().c_str(),
 
170
                      dep_str.c_str(), dep_str.c_str());
 
171
        DRIZZLE_ABORT;
 
172
      }
 
173
 
 
174
      ++handle_deps;
 
175
    }
 
176
    ++map_iter;
 
177
  }
 
178
  deps_built_= true;
 
179
}
 
180
 
188
181
module::Registry::ModuleList module::Registry::getList()
189
182
{
 
183
  if (not deps_built_)
 
184
  {
 
185
    buildDeps();
 
186
  }
 
187
 
190
188
  std::vector<module::Module *> plugins;
191
189
 
192
 
  std::cout << "In module::Registry::getList" << std::endl;
193
 
  
194
190
  VertexList vertex_list;
195
191
 
196
192
  boost::topological_sort(depend_graph_, std::back_inserter(vertex_list));
197
193
 
198
 
  std::cout << "plugin load ordering: ";
199
194
  for (VertexList::iterator i = vertex_list.begin();
200
195
       i != vertex_list.end(); ++i)
201
196
  {
202
 
    std::cout << properties(*i).getName() << " ";
203
 
    if (properties(*i).getModule() != NULL)
 
197
    Module *mod_ptr= properties(*i).getModule();
 
198
    if (mod_ptr != NULL)
204
199
    {
205
 
      plugins.push_back(properties(*i).getModule());
 
200
      plugins.push_back(mod_ptr);
206
201
    }  
207
202
  }
208
 
  std::cout << std::endl;
209
203
 
210
204
  return plugins;
211
205
}