Exemple #1
0
bool PluginManager::loadByPath(const std::string& pluginPath,
    PF_PluginType type)
{
    // Only filenames that start with libpdal_plugin are candidates to be loaded
    // at runtime.  PDAL plugins are to be named in a specified form:

    // libpdal_plugin_{stagetype}_{name}

    // For example, libpdal_plugin_writer_text or libpdal_plugin_filter_color

    bool loaded(false);

    boost::filesystem::path path(pluginPath);
    std::string pathname = Utils::tolower(path.filename().string());

    // If we are a valid type, and we're not yet already
    // loaded in the LibraryMap, load it.
    if (pluginTypeValid(pathname, type) &&
        m_dynamicLibraryMap.find(path.string()) == m_dynamicLibraryMap.end())
    {
        std::string errorString;
        auto completePath(boost::filesystem::complete(path).string());

        if (DynamicLibrary *d = loadLibrary(completePath, errorString))
        {
            if (PF_InitFunc initFunc =
                    (PF_InitFunc)(d->getSymbol("PF_initPlugin")))
            {
                loaded = initializePlugin(initFunc);
            }
        }
    }

    return loaded;
}
Exemple #2
0
bool PluginManager::loadByPath(const std::string& pluginPath, int type)
{
    // Only filenames that start with libpdal_plugin are candidates to be loaded
    // at runtime.  PDAL plugins are to be named in a specified form:

    // libpdal_plugin_{stagetype}_{name}

    // For example, libpdal_plugin_writer_text or libpdal_plugin_filter_color

    bool loaded(false);

    std::string filename = Utils::tolower(FileUtils::getFilename(pluginPath));

    // If we are a valid type, and we're not yet already
    // loaded in the LibraryMap, load it.

    Log log("PDAL", "stderr");

    if (pluginTypeValid(filename, type) && !libraryLoaded(pluginPath))
    {
        std::string errorString;
        auto completePath(FileUtils::toAbsolutePath(pluginPath));

        log.get(LogLevel::Debug) << "Attempting to load plugin '" <<
            completePath << "'." << std::endl;

        if (DynamicLibrary *d = loadLibrary(completePath, errorString))
        {
            log.get(LogLevel::Debug) << "Loaded plugin '" << completePath <<
                "'." << std::endl;
            if (PF_InitFunc initFunc =
                    (PF_InitFunc)(d->getSymbol("PF_initPlugin")))
            {
                loaded = initializePlugin(initFunc);
                log.get(LogLevel::Debug) << "Initialized plugin '" <<
                    completePath << "'." << std::endl;
            }
            else
                log.get(LogLevel::Error) << "Failed to initialize plugin function for plugin '" <<
                    completePath << "'." << std::endl;
        }
    }

    return loaded;
}