Archive / / / modules.cpp
2007-09-19 22:54:42 UTC
previous next
#include <boost/scoped_ptr.hpp> #include <boost/filesystem/path.hpp> #include <boost/filesystem/operations.hpp> #include <boost/format.hpp> #include <dlfcn.h> #include <string> #include "modules.h" using namespace boost::filesystem; namespace Modules { boost::scoped_ptr<Manager> manager; Manager::Manager() { // TODO: Load the list of modules from a config file instead // TODO: Make the order of the list not matter by looping through // the list until the same modules fail to load in two consecutive loops // TODO: Make what used to the the server's log messages do something // constructive for the client directory_iterator end_itr; for (directory_iterator it(initial_path()); it != end_itr; it++) if (it->leaf().find("m_cli_") == 0) { dlerror(); // Clear any previous error messages void *handle = dlopen(it->string().c_str(), RTLD_NOW); if (!handle) { // log::error(boost::str(boost::format( // "Could not open module '%1%', error was: %2%") // % it->leaf() % dlerror())); } else { // log::info(boost::str(boost::format( // "Loaded module '%1%'") % it->leaf())); _modules.push_back(handle); } } } Manager::~Manager() { for (std::list<void*>::iterator it = _modules.begin(); it != _modules.end(); it++) dlclose(*it); } }