std::vector<std::string> DriverManager::GetDriverNames(const std::string& path) { fs::path driver_path(driver_path_default); if (!fs::is_directory(driver_path)) { std::cerr << "Error : Path " << fs::absolute(driver_path) << " is not a directory." << std::endl; exit(EXIT_FAILURE); } std::vector<std::string> res; fs::directory_iterator path_it(driver_path), end; // loop through each subdirectory in 'driver_path' for (; path_it != end; path_it++) { // if not a regular file, move on if (!fs::is_regular_file(path_it->path())) { continue; } // get filename from path iterator auto filename = path_it->path().filename().string(); // store matches into a string match result std::smatch sm; // if it matches - add it to the result if (std::regex_match(filename, sm, cppdb::driver_file_regex)) { res.push_back(sm[1]); } } return res; }
void PluginManager::l_loadAll(PF_PluginType type) { std::string driver_path("PDAL_DRIVER_PATH"); std::string pluginDir = Utils::getenv(driver_path); // If we don't have a driver path, defaults are set. if (pluginDir.size() == 0) { std::ostringstream oss; oss << PDAL_PLUGIN_INSTALL_PATH << ":/usr/local/lib:./lib:../lib:../bin"; pluginDir = oss.str(); } std::vector<std::string> pluginPathVec = Utils::split2(pluginDir, ':'); for (const auto& pluginPath : pluginPathVec) loadAll(pluginPath, type); }
void DriverManager::LoadDrivers(const std::string& path) { fs::path driver_path(driver_path_default); if (!fs::is_directory(driver_path)) { std::cerr << "Error : Path " << fs::absolute(driver_path) << " is not a directory." << std::endl; exit(EXIT_FAILURE); } std::vector<std::string> res; fs::directory_iterator path_it(driver_path), end; for (; path_it != end; path_it++) { // if not a regular file, move on if (!fs::is_regular_file(path_it->path())) { continue; } // get filename from path iterator auto file_path = path_it->path(); // store matches into a string match result std::smatch sm; // if it matches - add it to the result if (std::regex_match(file_path.filename().string(), sm, cppdb::driver_file_regex)) { void* handle = dlopen(fs::absolute(file_path).string().c_str(), RTLD_LAZY); if (handle == nullptr) { std::cerr << "Could not dlopen file '" << file_path.filename().string() << "'\n"; std::cerr << " " << dlerror() << std::endl; exit(1); } _driver_libraries[sm[1]] = handle; } } DriverManager::_drivers_loaded = true; }
bool PluginManager::guessLoadByPath(const std::string& driverName) { // parse the driver name into an expected pluginName, e.g., // writers.las => libpdal_plugin_writer_las std::vector<std::string> driverNameVec; driverNameVec = Utils::split2(driverName, '.'); std::string pluginName = "libpdal_plugin_" + driverNameVec[0] + "_" + driverNameVec[1]; std::string driver_path("PDAL_DRIVER_PATH"); std::string pluginDir = Utils::getenv(driver_path); // Default path below if not set. if (pluginDir.size() == 0) { std::ostringstream oss; oss << PDAL_PLUGIN_INSTALL_PATH << ":/usr/local/lib:./lib:../lib:../bin"; pluginDir = oss.str(); } Log("PDAL", "stderr").get(LogLevel::Debug) << "Plugin search path '" << pluginDir << "'" << std::endl; std::vector<std::string> pluginPathVec = Utils::split2(pluginDir, ':'); for (const auto& pluginPath : pluginPathVec) { if (!FileUtils::fileExists(pluginPath) || !FileUtils::isDirectory(pluginPath)) continue; StringList files = FileUtils::directoryList(pluginPath); for (auto file : files) { if ((FileUtils::extension(file) != dynamicLibraryExtension) || FileUtils::isDirectory(file)) continue; std::string stem = FileUtils::stem(file); std::string::size_type pos = stem.find_last_of('_'); if (pos == std::string::npos || pos == stem.size() - 1 || stem.substr(pos + 1) != driverNameVec[1]) continue; PF_PluginType type; if (driverNameVec[0] == "readers") type = PF_PluginType_Reader; else if (driverNameVec[0] == "kernels") type = PF_PluginType_Kernel; else if (driverNameVec[0] == "filters") type = PF_PluginType_Filter; else if (driverNameVec[0] == "writers") type = PF_PluginType_Writer; else type = PF_PluginType_Reader; if (loadByPath(file, type)) return true; } } return false; }
bool PluginManager::guessLoadByPath(const std::string& driverName) { // parse the driver name into an expected pluginName, e.g., // writers.las => libpdal_plugin_writer_las std::vector<std::string> driverNameVec; driverNameVec = Utils::split2(driverName, '.'); std::string pluginName = "libpdal_plugin_" + driverNameVec[0] + "_" + driverNameVec[1]; std::string driver_path("PDAL_DRIVER_PATH"); std::string pluginDir = Utils::getenv(driver_path); // Default path below if not set. if (pluginDir.size() == 0) { std::ostringstream oss; oss << PDAL_PLUGIN_INSTALL_PATH << ":/usr/local/lib:./lib:../lib:../bin"; pluginDir = oss.str(); } std::string plugin_debug("PDAL_DEBUG"); std::string plugin_debug_path = Utils::getenv(plugin_debug); if (plugin_debug_path.size()) { std::cerr << "PDAL: plugin search path '" << pluginDir <<"'"<<std::endl; } std::vector<std::string> pluginPathVec = Utils::split2(pluginDir, ':'); for (const auto& pluginPath : pluginPathVec) { boost::filesystem::path path(pluginPath); if (!FileUtils::fileExists(path.string()) || !boost::filesystem::is_directory(path)) continue; boost::filesystem::directory_iterator dir(path), it, end; // Looks like directory_iterator doesn't support range-based for loop in // Boost v1.55. It fails Travis anyway, so I reverted it. for (it = dir; it != end; ++it) { boost::filesystem::path full_path = it->path(); if (boost::filesystem::is_directory(full_path)) continue; std::string ext = full_path.extension().string(); if (ext != dynamicLibraryExtension) continue; std::string stem = full_path.stem().string(); std::string::size_type pos = stem.find_last_of('_'); if (pos == std::string::npos || pos == stem.size() - 1 || stem.substr(pos + 1) != driverNameVec[1]) continue; PF_PluginType type; if (driverNameVec[0] == "readers") type = PF_PluginType_Reader; else if (driverNameVec[0] == "kernels") type = PF_PluginType_Kernel; else if (driverNameVec[0] == "filters") type = PF_PluginType_Filter; else if (driverNameVec[0] == "writers") type = PF_PluginType_Writer; else type = PF_PluginType_Reader; if (loadByPath(full_path.string(), type)) { return true; } } } return false; }