62 lines
1.5 KiB
C++
62 lines
1.5 KiB
C++
#include <cstdlib>
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
#include <iostream>
|
|
|
|
#include <boost/algorithm/string.hpp>
|
|
#include <boost/filesystem.hpp>
|
|
#include <boost/dll/import.hpp>
|
|
|
|
#include "interface.hpp"
|
|
|
|
using std::string;
|
|
using std::vector;
|
|
|
|
namespace fs = boost::filesystem;
|
|
namespace dll = boost::dll;
|
|
|
|
const vector<string> &get_plugin_dirs() {
|
|
static vector<string> result;
|
|
if (!result.empty()) {
|
|
return result;
|
|
}
|
|
|
|
#ifdef _WIN32
|
|
const string delimiter = ";";
|
|
#else
|
|
const string delimiter = ":";
|
|
#endif
|
|
const char *plugin_dirs = std::getenv("LOADER_PLUGIN_DIRS");
|
|
if (plugin_dirs != nullptr && *plugin_dirs != '\0') {
|
|
boost::split(result, plugin_dirs, boost::is_any_of(delimiter));
|
|
}
|
|
|
|
if (result.empty()) {
|
|
result.push_back("/usr/lib/loader");
|
|
result.push_back("/usr/local/lib/loader");
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
int main() {
|
|
const vector<string> &plugin_dirs = get_plugin_dirs();
|
|
for (const auto &plugin_dir : plugin_dirs) {
|
|
fs::path plugin_path(plugin_dir);
|
|
|
|
if (!fs::is_directory(plugin_path)) {
|
|
continue;
|
|
}
|
|
for (fs::recursive_directory_iterator dir(plugin_path), end; dir != end; ++dir) {
|
|
boost::shared_ptr<Interface> plugin;
|
|
plugin = dll::import_symbol<Interface>(
|
|
dir->path(),
|
|
"plugin",
|
|
dll::load_mode::rtld_lazy
|
|
);
|
|
std::cout << "loading plugin: " << plugin->name() << std::endl;
|
|
}
|
|
}
|
|
}
|