void PluginManager::loadAll(const std::string& pluginDirectory, PF_PluginType type) { const bool pluginDirectoryValid = pluginDirectory.size() && (FileUtils::fileExists(pluginDirectory) || boost::filesystem::is_directory(pluginDirectory)); if (pluginDirectoryValid) { boost::filesystem::directory_iterator dir(pluginDirectory), 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; loadByPath(full_path.string(), type); } } }
bool PluginManager::l_loadPlugin(const std::string& driverFileName) { std::vector<std::string> driverPathVec; driverPathVec = Utils::split2(driverFileName, '.'); if ((FileUtils::extension(driverFileName) != dynamicLibraryExtension) || FileUtils::isDirectory(driverFileName)) return false; std::vector<std::string> driverNameVec; driverNameVec = Utils::split2(driverPathVec[0], '_'); std::string ptype; if (driverNameVec.size() >= 3) ptype = driverNameVec[2]; PF_PluginType type; if (Utils::iequals(ptype, "reader")) type = PF_PluginType_Reader; else if (Utils::iequals(ptype,"kernel")) type = PF_PluginType_Kernel; else if (Utils::iequals(ptype, "filter")) type = PF_PluginType_Filter; else if (Utils::iequals(ptype, "writer")) type = PF_PluginType_Writer; else throw pdal_error("Unknown plugin type '" + ptype + "'"); return loadByPath(driverFileName, type); }
void PluginManager::loadAll(const std::string& pluginDirectory, int type) { const bool pluginDirectoryValid = pluginDirectory.size() && (FileUtils::fileExists(pluginDirectory) || FileUtils::isDirectory(pluginDirectory)); if (pluginDirectoryValid) { StringList files = FileUtils::directoryList(pluginDirectory); for (auto file : files) { if ((FileUtils::extension(file) == dynamicLibraryExtension) && !FileUtils::isDirectory(file)) loadByPath(file, type); } } }
bool PluginManager::loadPlugin(const std::string& driverFileName) { std::vector<std::string> driverPathVec; driverPathVec = Utils::split2(driverFileName, '.'); boost::filesystem::path full_path(driverFileName); if (boost::filesystem::is_directory(full_path)) return false; std::string ext = full_path.extension().string(); if (ext != dynamicLibraryExtension) return false; std::string stem = full_path.stem().string(); std::vector<std::string> driverNameVec; driverNameVec = Utils::split2(driverPathVec[0], '_'); std::string ptype; if (driverNameVec.size() >=3) ptype = driverNameVec[2]; PF_PluginType type; if (Utils::iequals(ptype, "reader")) type = PF_PluginType_Reader; else if (Utils::iequals(ptype,"kernel")) type = PF_PluginType_Kernel; else if (Utils::iequals(ptype, "filter")) type = PF_PluginType_Filter; else if (Utils::iequals(ptype, "writer")) type = PF_PluginType_Writer; else throw pdal_error("Unknown plugin type '" + ptype +"'"); if (loadByPath(full_path.string(), type)) { return true; } return false; }
uv_err_t UVDPluginEngine::loadByName(const std::string &name) { /* We could also scan over plugin dirs and see if any match But, current strategy seems to preload them all, so point is mute */ //We could prob link some Boost in and make this easier std::string path; //Already loaded? if( m_loadedPlugins.find(name) != m_loadedPlugins.end() ) { printf_plugin_debug("duplicate lodaing of %s\n", name.c_str()); return UV_ERR_OK; } path = std::string("lib") + name + ".so"; uv_assert_err_ret(loadByPath(path)); return UV_ERR_OK; }
bool FileCache::load(const std::string &name, std::ostream &os) { std::string path = m_dir + DIR_DELIM + name; return loadByPath(path, os); }
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; }
uv_err_t UVDPluginEngine::loadByDir(const std::string &pluginDir, UVDConfig *config, bool recursive, bool failOnError, bool failOnPluginError) { //boost throws exceptions //TODO: move to UVD friendly adapter interface try { for( boost::filesystem::directory_iterator iter(pluginDir); iter != boost::filesystem::directory_iterator(); ++iter ) { //Not necessarily canonical std::string path; uv_err_t loadByPathRc = UV_ERR_GENERAL; path = pluginDir + "/" + iter->path().filename(); if( is_directory(iter->status()) ) { if( recursive ) { uv_assert_err_ret(loadByDir(path, config, recursive, failOnError, failOnPluginError)); } continue; } //Try loading it, ignoring errors since it might just be a plugin config file or something //We should print a warning if loadByPathRc = loadByPath(path, false); if( UV_FAILED(loadByPathRc) ) { if( loadByPathRc == UV_ERR_NOTSUPPORTED ) { if( failOnError ) { printf_error("failed to load possible plugin: %s\n", path.c_str()); return UV_DEBUG(UV_ERR_GENERAL); } else { printf_plugin_debug("failed to load possible plugin: %s\n", path.c_str()); } } else { if( failOnError || failOnPluginError ) { printf_error("failed to load plugin: %s\n", path.c_str()); return UV_DEBUG(UV_ERR_GENERAL); } else { printf_warn("failed to load plugin: %s\n", path.c_str()); } } } } return UV_ERR_OK; } catch(...) { if( !config->m_suppressErrors ) { printf_error("failed to load plugin dir %s\n", pluginDir.c_str()); } if( config->m_ignoreErrors ) { return UV_DEBUG(UV_ERR_WARNING); } else { return UV_DEBUG(UV_ERR_GENERAL); } } }