|
From: Lasse Kärkkäi. <tr...@us...> - 2009-06-28 21:22:29
|
Module: performous Branch: master Commit: efe70a24add6e6a4d4f86c0f62726a414c206f74 Author: Lasse Kärkkäinen <tronic+ndrm at trn.iki.fi> Date: Mon Jun 29 00:21:21 2009 +0300 Further library restructuring to avoid plugin++ boost deps (for those who only use plugin::dll). --- libs/libda/src/audio.cpp | 2 +- libs/plugin++/include/plugin++/dll.hpp | 45 +------------------------ libs/plugin++/include/plugin++/loader.hpp | 52 +++++++++++++++++++++++++++++ libs/plugin++/src/dll-posix.cpp | 2 +- libs/plugin++/src/dll-windows.cpp | 2 +- 5 files changed, 56 insertions(+), 47 deletions(-) diff --git a/libs/libda/src/audio.cpp b/libs/libda/src/audio.cpp index 1c01789..bfff922 100644 --- a/libs/libda/src/audio.cpp +++ b/libs/libda/src/audio.cpp @@ -1,5 +1,5 @@ #include <libda/audio_dev.hpp> -#include <plugin++/dll.hpp> +#include <plugin++/loader.hpp> #include <ostream> #include <limits> diff --git a/libs/plugin++/include/plugin++/dll.hpp b/libs/plugin++/include/plugin++/dll.hpp index 62ab4be..19100f5 100644 --- a/libs/plugin++/include/plugin++/dll.hpp +++ b/libs/plugin++/include/plugin++/dll.hpp @@ -1,59 +1,16 @@ #ifndef DLL_HPP_INCLUDED #define DLL_HPP_INCLUDED -#include <iostream> -#include <set> -#include <sstream> #include <string> -#include <boost/filesystem.hpp> -#include <boost/ptr_container/ptr_vector.hpp> namespace plugin { - namespace fs = boost::filesystem; - /** @short RAII wrapper to load and unload dynamic library **/ class dll { void* lib; public: - dll(fs::path const& filename); + dll(std::string const& filename); ~dll(); }; - - /** @short A helper for loading all matching libraries in a folder. **/ - class loader { - boost::ptr_vector<dll> dlls; - void parse(std::set<fs::path>& paths, char const* var, fs::path const& folder = fs::path()) { - if (!var) return; - std::istringstream iss(var); - std::string elem; - while (std::getline(iss, elem, ':')) { - fs::path p = elem; - if (!folder.empty()) p /= folder; - if (fs::is_directory(p)) paths.insert(p); - } - } - /** Try to load all libraries in the given folder. **/ - void load(fs::path const& path) { - for (fs::directory_iterator it(path), end; it != end; ++it) { - try { - dlls.push_back(new dll(*it)); - } catch (std::runtime_error const& e) { - std::cerr << e.what() << std::endl; - } - } - } - public: - loader(fs::path const& folder) { - std::set<fs::path> paths; - parse(paths, std::getenv("PLUGIN_PATH")); - if (!folder.empty()) { - parse(paths, std::getenv("LD_LIBRARY_PATH"), folder); - parse(paths, "/usr/lib:/usr/local/lib", folder); - } - for (std::set<fs::path>::const_iterator it = paths.begin(); it != paths.end(); ++it) load(*it); - if (dlls.empty()) std::cerr << "No plugins found. Try setting PLUGIN_PATH or LD_LIBRARY_PATH." << std::endl; - } - }; } #endif diff --git a/libs/plugin++/include/plugin++/loader.hpp b/libs/plugin++/include/plugin++/loader.hpp new file mode 100644 index 0000000..7977043 --- /dev/null +++ b/libs/plugin++/include/plugin++/loader.hpp @@ -0,0 +1,52 @@ +#ifndef LOADER_HPP_INCLUDED +#define LOADER_HPP_INCLUDED + +#include "dll.hpp" +#include <iostream> +#include <set> +#include <sstream> +#include <boost/filesystem.hpp> +#include <boost/ptr_container/ptr_vector.hpp> + +namespace plugin { + namespace fs = boost::filesystem; + + /** @short A helper for loading all matching libraries in a folder. **/ + class loader { + boost::ptr_vector<dll> dlls; + void parse(std::set<fs::path>& paths, char const* var, fs::path const& folder = fs::path()) { + if (!var) return; + std::istringstream iss(var); + std::string elem; + while (std::getline(iss, elem, ':')) { + fs::path p = elem; + if (!folder.empty()) p /= folder; + if (fs::is_directory(p)) paths.insert(p); + } + } + /** Try to load all libraries in the given folder. **/ + void load(fs::path const& path) { + for (fs::directory_iterator it(path), end; it != end; ++it) { + try { + dlls.push_back(new dll(it->string())); + } catch (std::runtime_error const& e) { + std::cerr << e.what() << std::endl; + } + } + } + public: + loader(fs::path const& folder) { + std::set<fs::path> paths; + parse(paths, std::getenv("PLUGIN_PATH")); + if (!folder.empty()) { + parse(paths, std::getenv("LD_LIBRARY_PATH"), folder); + parse(paths, "/usr/lib:/usr/local/lib", folder); + } + for (std::set<fs::path>::const_iterator it = paths.begin(); it != paths.end(); ++it) load(*it); + if (dlls.empty()) std::cerr << "No plugins found. Try setting PLUGIN_PATH or LD_LIBRARY_PATH." << std::endl; + } + }; +} + +#endif + diff --git a/libs/plugin++/src/dll-posix.cpp b/libs/plugin++/src/dll-posix.cpp index 6dad599..1f71043 100644 --- a/libs/plugin++/src/dll-posix.cpp +++ b/libs/plugin++/src/dll-posix.cpp @@ -4,7 +4,7 @@ #include <stdexcept> namespace plugin { - dll::dll(fs::path const& filename): lib(dlopen(filename.string().c_str(), RTLD_LAZY | RTLD_GLOBAL)) { + dll::dll(std::string const& filename): lib(dlopen(filename.c_str(), RTLD_LAZY | RTLD_GLOBAL)) { if (!lib) throw std::runtime_error(dlerror()); } diff --git a/libs/plugin++/src/dll-windows.cpp b/libs/plugin++/src/dll-windows.cpp index af75c65..8a10412 100644 --- a/libs/plugin++/src/dll-windows.cpp +++ b/libs/plugin++/src/dll-windows.cpp @@ -4,7 +4,7 @@ #include <stdexcept> namespace plugin { - dll::dll(fs::path const& filename): lib(LoadLibrary(filename.string().c_str())) { + dll::dll(std::string const& filename): lib(LoadLibrary(filename.c_str())) { if (!lib) throw std::runtime_error(dlerror()); } |