26#include <drizzled/module/registry.h>
27#include <drizzled/module/library.h>
28#include <drizzled/module/graph.h>
29#include <drizzled/module/vertex_handle.h>
31#include <drizzled/plugin.h>
33#include <drizzled/cursor.h>
34#include <drizzled/abort_exception.h>
35#include <drizzled/util/find_ptr.h>
37#include <boost/bind/bind.hpp>
43module::Registry::Registry() :
45 depend_graph_(new module::Graph()),
51module::Registry::~Registry()
58 for (plugin::Plugin::map::reference it : plugin_registry)
59 it.second->shutdownPlugin();
66 std::vector<plugin::Plugin::owned_ptr> error_plugins;
67 for (
auto it= plugin_registry.begin(); it != plugin_registry.end(); )
69 if (it->second->removeLast())
71 error_plugins.push_back(std::move(it->second));
72 it= plugin_registry.erase(it);
76 it= plugin_registry.erase(it);
81 error_plugins.clear();
88 for (ModuleMap::reference it : module_registry_)
90 module_registry_.clear();
92 for (LibraryMap::reference it : library_registry_)
94 library_registry_.clear();
97module::Module* module::Registry::find(
const std::string& name)
99 return find_ptr2(module_registry_, boost::to_lower_copy(name));
102void module::Registry::add(module::Module *handle)
104 std::string add_str(boost::to_lower_copy(handle->getName()));
106 module_registry_[add_str]= handle;
108 Vertex vertex_info(add_str, handle);
109 VertexDesc handle_vertex= boost::add_vertex(depend_graph_->getGraph());
110 depend_graph_->properties(handle_vertex)= vertex_info;
112 handle->setVertexHandle(
new VertexHandle(handle_vertex));
115void module::Registry::remove(module::Module *handle)
117 module_registry_.erase(boost::to_lower_copy(handle->getName()));
120void module::Registry::buildDeps()
122 for (ModuleMap::reference map_iter : module_registry_)
124 Module* handle= map_iter.second;
125 for (Module::Depends::const_reference handle_deps : handle->getDepends())
127 std::string dep_str(boost::to_lower_copy(handle_deps));
128 bool found_dep=
false;
129 for (vertex_iter it= boost::vertices(depend_graph_->getGraph()).first; it != vertices(depend_graph_->getGraph()).second; it++)
131 if (depend_graph_->properties(*it).getName() == dep_str)
134 add_edge(handle->getVertexHandle()->getVertexDesc(), *it, depend_graph_->getGraph());
140 errmsg_printf(error::ERROR, _(
"Couldn't process plugin module dependencies. %s depends on %s but %s is not to be loaded.\n"),
141 handle->getName().c_str(), dep_str.c_str(), dep_str.c_str());
149module::Registry::ModuleList module::Registry::getList()
153 VertexList vertex_list;
154 boost::topological_sort(depend_graph_->getGraph(), std::back_inserter(vertex_list));
156 for (VertexList::reference it : vertex_list)
158 if (Module* mod_ptr= depend_graph_->properties(it).getModule())
159 plugins.push_back(mod_ptr);
164module::Library *module::Registry::addLibrary(
const std::string &plugin_name,
bool builtin)
167 module::Library *library= findLibrary(plugin_name);
171 library= module::Library::loadLibrary(plugin_name, builtin);
175 library_registry_.insert(make_pair(plugin_name, library));
180void module::Registry::removeLibrary(
const std::string &plugin_name)
182 LibraryMap::iterator iter= library_registry_.find(plugin_name);
183 if (iter != library_registry_.end())
186 library_registry_.erase(iter);
190module::Library *module::Registry::findLibrary(
const std::string &plugin_name)
const
192 return find_ptr2(library_registry_, plugin_name);
195void module::Registry::shutdownModules()
197 module_shutdown(*
this);
TODO: Rename this file - func.h is stupid.