# HG changeset patch # User Lucas Thompson # Date 1486725319 0 # Node ID d9511f9e04d74c7a6d43871ec62d62416d77bb72 # Parent da5f4d37988d7807d5236745bdd658484c5f9691 Introduce some POD structs for describing an external server application and the desired libraries to load from it, and disambiguating between empty list request and invalid list request. This allows for overriding PiperVampPluginFactory behaviour for using a PluginScan to populate the list request. diff -r da5f4d37988d -r d9511f9e04d7 plugin/PiperVampPluginFactory.cpp --- a/plugin/PiperVampPluginFactory.cpp Thu Feb 09 14:32:07 2017 +0000 +++ b/plugin/PiperVampPluginFactory.cpp Fri Feb 10 11:15:19 2017 +0000 @@ -39,6 +39,7 @@ #include #include +#include #include "base/Profiler.h" #include "base/HelperExecPath.h" @@ -54,14 +55,17 @@ } }; -PiperVampPluginFactory::PiperVampPluginFactory(std::initializer_list servers) : +PiperVampPluginFactory::PiperVampPluginFactory(std::initializer_list servers) : m_logger(new Logger) { HelperExecPath hep(HelperExecPath::AllInstalled); for (auto server: servers) { - for (auto platformHelper: hep.getHelperExecutables(server)) + for (auto platformHelper: hep.getHelperExecutables(QString::fromStdString(server.name))) m_servers.push_back(platformHelper); + if (server.hasDesiredExtractors) { + setDesiredExtractors(server.name, server.extractors); + } } for (auto n: m_servers) { @@ -72,21 +76,36 @@ if (m_servers.empty()) { SVDEBUG << "NOTE: No Piper Vamp servers found in installation;" << " found none of the following:" << endl; - for (auto serverName: servers) - for (auto d: hep.getHelperCandidatePaths(serverName)) { + for (auto server: servers) + for (auto d: hep.getHelperCandidatePaths(QString::fromStdString(server.name))) { SVDEBUG << "NOTE: " << d << endl; } } } PiperVampPluginFactory::PiperVampPluginFactory() : - PiperVampPluginFactory({"piper-vamp-simple-server"}) {} + PiperVampPluginFactory({{"piper-vamp-simple-server"}}) {} PiperVampPluginFactory::~PiperVampPluginFactory() { delete m_logger; } +void +PiperVampPluginFactory::setDesiredExtractors(ServerName name, + DesiredExtractors extractors) +{ + const bool isValidServerName = std::find_if( + m_servers.begin(), + m_servers.end(), + [&name](const HelperExecPath::HelperExec &h) -> bool { + return QFileInfo(h.executable).fileName().toStdString() == name; + }) != m_servers.end(); + if ( isValidServerName ) { + m_overrideDesiredExtractors[name] = extractors; + } +} + vector PiperVampPluginFactory::getPluginIdentifiers(QString &errorMessage) { @@ -188,35 +207,55 @@ { QString tag = server.tag; string executable = server.executable.toStdString(); + const string serverName = QFileInfo(server.executable).fileName().toStdString(); + + DesiredSubset from; + + if (m_overrideDesiredExtractors.find(serverName) != m_overrideDesiredExtractors.end()) { + const auto desired = m_overrideDesiredExtractors.at(serverName); + if (desired.allAvailable) { + if (desired.from.empty()) { + from = {}; + } else { + // ambiguous struct + return; + } + } else { + if (desired.from.empty()) { + // ambigous + return; + } else { + from = desired.from; + } + } + } else { + PluginScan *scan = PluginScan::getInstance(); + auto candidateLibraries = + scan->getCandidateLibrariesFor(PluginScan::VampPlugin); - PluginScan *scan = PluginScan::getInstance(); - auto candidateLibraries = - scan->getCandidateLibrariesFor(PluginScan::VampPlugin); + SVDEBUG << "PiperVampPluginFactory: Populating from " << executable << endl; + SVDEBUG << "INFO: Have " << candidateLibraries.size() + << " candidate Vamp plugin libraries from scanner" << endl; + for (const auto &c: candidateLibraries) { + if (c.helperTag == tag) { + string soname = QFileInfo(c.libraryPath).baseName().toStdString(); + SVDEBUG << "INFO: For tag \"" << tag << "\" giving library " << soname << endl; + from.push_back(soname); + } + } - SVDEBUG << "PiperVampPluginFactory: Populating from " << executable << endl; - SVDEBUG << "INFO: Have " << candidateLibraries.size() - << " candidate Vamp plugin libraries from scanner" << endl; - - vector from; - for (const auto &c: candidateLibraries) { - if (c.helperTag == tag) { - string soname = QFileInfo(c.libraryPath).baseName().toStdString(); - SVDEBUG << "INFO: For tag \"" << tag << "\" giving library " << soname << endl; - from.push_back(soname); - } - } - - if (from.empty()) { - SVDEBUG << "PiperVampPluginFactory: No candidate libraries for tag \"" - << tag << "\""; - if (scan->scanSucceeded()) { - // we have to assume that they all failed to load (i.e. we - // exclude them all) rather than sending an empty list - // (which would mean no exclusions) - SVDEBUG << ", skipping" << endl; - return; - } else { - SVDEBUG << ", but it seems the scan failed, so bumbling on anyway" << endl; + if (from.empty()) { + SVDEBUG << "PiperVampPluginFactory: No candidate libraries for tag \"" + << tag << "\""; + if (scan->scanSucceeded()) { + // we have to assume that they all failed to load (i.e. we + // exclude them all) rather than sending an empty list + // (which would mean no exclusions) + SVDEBUG << ", skipping" << endl; + return; + } else { + SVDEBUG << ", but it seems the scan failed, so bumbling on anyway" << endl; + } } } diff -r da5f4d37988d -r d9511f9e04d7 plugin/PiperVampPluginFactory.h --- a/plugin/PiperVampPluginFactory.h Thu Feb 09 14:32:07 2017 +0000 +++ b/plugin/PiperVampPluginFactory.h Fri Feb 10 11:15:19 2017 +0000 @@ -34,8 +34,35 @@ class PiperVampPluginFactory : public FeatureExtractionPluginFactory { public: + using ServerName = std::string; + using DesiredSubset = std::vector; + struct DesiredExtractors + { + DesiredExtractors() : allAvailable(false) {} // filtered, but invalid, by default (from should not be empty) + + DesiredExtractors(DesiredSubset subset) + : allAvailable(subset.empty()), from(subset) {} // if empty assume all available are wanted, can populate struct manually if not + + bool allAvailable; // used to disambiguate an empty filter list from wanting all available extractors, client code should inspect both to determine validity + DesiredSubset from; // this should only be populated if allAvailable is false + }; + + struct ServerDescription + { + ServerDescription(ServerName n) + : name(n), hasDesiredExtractors(false) {} // fall back to populating using PluginScan internally + ServerDescription(ServerName n, DesiredSubset desired) + : name(n), hasDesiredExtractors(true), extractors(desired) {} + ServerName name; + bool hasDesiredExtractors; // indicates whether to override the ListRequest made internally + DesiredExtractors extractors; // for populating the from field in a ListRequest + }; + PiperVampPluginFactory(); - PiperVampPluginFactory(std::initializer_list servers); + PiperVampPluginFactory(std::initializer_list servers); + + virtual void setDesiredExtractors(ServerName name, DesiredExtractors extractors); + virtual ~PiperVampPluginFactory(); virtual std::vector getPluginIdentifiers(QString &errorMessage) @@ -56,6 +83,7 @@ std::map m_origins; // plugin identifier -> server path std::map m_pluginData; // identifier -> data std::map m_taxonomy; // identifier -> category string + std::map m_overrideDesiredExtractors; void populate(QString &errorMessage); void populateFrom(const HelperExecPath::HelperExec &, QString &errorMessage);