Example #1
0
vector<PluginLoader::PluginKey>
PluginLoader::Impl::enumeratePlugins(Enumeration enumeration)
{
    string libraryName, identifier;
    if (enumeration.type == Enumeration::SinglePlugin) {
        decomposePluginKey(enumeration.key, libraryName, identifier);
    }
    
    vector<string> fullPaths = listLibraryFilesFor(enumeration);

    // For these we should warn if a plugin can be loaded from a library
    bool specific = (enumeration.type == Enumeration::SinglePlugin ||
                     enumeration.type == Enumeration::InLibraries);

    vector<PluginKey> added;
    
    for (size_t i = 0; i < fullPaths.size(); ++i) {

        string fullPath = fullPaths[i];
        void *handle = Files::loadLibrary(fullPath);
        if (!handle) continue;
            
        VampGetPluginDescriptorFunction fn =
            (VampGetPluginDescriptorFunction)Files::lookupInLibrary
            (handle, "vampGetPluginDescriptor");
            
        if (!fn) {
            if (specific) {
                cerr << "Vamp::HostExt::PluginLoader: "
                    << "No vampGetPluginDescriptor function found in library \""
                     << fullPath << "\"" << endl;
            }
            Files::unloadLibrary(handle);
            continue;
        }
            
        int index = 0;
        const VampPluginDescriptor *descriptor = 0;
        bool found = false;
            
        while ((descriptor = fn(VAMP_API_VERSION, index))) {
            ++index;
            if (identifier != "") {
                if (descriptor->identifier != identifier) {
                    continue;
                }
            }
            found = true;
            PluginKey key = composePluginKey(fullPath, descriptor->identifier);
            if (m_pluginLibraryNameMap.find(key) ==
                m_pluginLibraryNameMap.end()) {
                m_pluginLibraryNameMap[key] = fullPath;
            }
            added.push_back(key);
        }

        if (!found && specific) {
            cerr << "Vamp::HostExt::PluginLoader: Plugin \""
                 << identifier << "\" not found in library \""
                 << fullPath << "\"" << endl;
        }
            
        Files::unloadLibrary(handle);
    }

    if (enumeration.type == Enumeration::All) {
        m_allPluginsEnumerated = true;
    }

    return added;
}
Example #2
0
void
PluginLoader::Impl::enumeratePlugins(PluginKey forPlugin)
{
    vector<string> path = PluginHostAdapter::getPluginPath();

    string libraryName, identifier;
    if (forPlugin != "") {
        if (!decomposePluginKey(forPlugin, libraryName, identifier)) {
            std::cerr << "WARNING: Vamp::HostExt::PluginLoader: Invalid plugin key \""
                      << forPlugin << "\" in enumerate" << std::endl;
            return;
        }
    }

    for (size_t i = 0; i < path.size(); ++i) {
        
        vector<string> files = listFiles(path[i], PLUGIN_SUFFIX);

        for (vector<string>::iterator fi = files.begin();
             fi != files.end(); ++fi) {
            
            if (libraryName != "") {
                // libraryName is lowercased and lacking an extension,
                // as it came from the plugin key
                string temp = *fi;
                for (size_t i = 0; i < temp.length(); ++i) {
                    temp[i] = tolower(temp[i]);
                }
                string::size_type pi = temp.find('.');
                if (pi == string::npos) {
                    if (libraryName != temp) continue;
                } else {
                    if (libraryName != temp.substr(0, pi)) continue;
                }
            }

            string fullPath = path[i];
            fullPath = splicePath(fullPath, *fi);
            void *handle = loadLibrary(fullPath);
            if (!handle) continue;
            
            VampGetPluginDescriptorFunction fn =
                (VampGetPluginDescriptorFunction)lookupInLibrary
                (handle, "vampGetPluginDescriptor");
            
            if (!fn) {
                unloadLibrary(handle);
                continue;
            }
            
            int index = 0;
            const VampPluginDescriptor *descriptor = 0;
            
            while ((descriptor = fn(VAMP_API_VERSION, index))) {
                ++index;
                if (identifier != "") {
                    if (descriptor->identifier != identifier) continue;
                }
                PluginKey key = composePluginKey(*fi, descriptor->identifier);
//                std::cerr << "enumerate: " << key << " (path: " << fullPath << ")" << std::endl;
                if (m_pluginLibraryNameMap.find(key) ==
                    m_pluginLibraryNameMap.end()) {
                    m_pluginLibraryNameMap[key] = fullPath;
                }
            }
            
            unloadLibrary(handle);
        }
    }

    if (forPlugin == "") m_allPluginsEnumerated = true;
}