changeset 1227:5d886b7b4029 piper

Error reporting for Piper server startup
author Chris Cannam
date Fri, 21 Oct 2016 16:24:30 +0100
parents 91ff08313375
children e699bdeef63c
files plugin/NativeVampPluginFactory.cpp plugin/NativeVampPluginFactory.h plugin/PiperVampPluginFactory.cpp plugin/PiperVampPluginFactory.h transform/TransformFactory.cpp transform/TransformFactory.h
diffstat 6 files changed, 64 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/plugin/NativeVampPluginFactory.cpp	Fri Oct 21 14:51:22 2016 +0100
+++ b/plugin/NativeVampPluginFactory.cpp	Fri Oct 21 16:24:30 2016 +0100
@@ -71,7 +71,7 @@
 }
 
 vector<QString>
-NativeVampPluginFactory::getPluginIdentifiers()
+NativeVampPluginFactory::getPluginIdentifiers(QString &)
 {
     Profiler profiler("NativeVampPluginFactory::getPluginIdentifiers");
 
--- a/plugin/NativeVampPluginFactory.h	Fri Oct 21 14:51:22 2016 +0100
+++ b/plugin/NativeVampPluginFactory.h	Fri Oct 21 16:24:30 2016 +0100
@@ -34,19 +34,20 @@
 public:
     virtual ~NativeVampPluginFactory() { }
 
-    virtual std::vector<QString> getPluginIdentifiers();
-    
-    virtual QString findPluginFile(QString soname, QString inDir = "");
+    virtual std::vector<QString> getPluginIdentifiers(QString &errorMessage)
+        override;
 
-    virtual piper_vamp::PluginStaticData getPluginStaticData(QString identifier);
+    virtual piper_vamp::PluginStaticData getPluginStaticData(QString identifier)
+        override;
 
     virtual Vamp::Plugin *instantiatePlugin(QString identifier,
-                                            sv_samplerate_t inputSampleRate);
+                                            sv_samplerate_t inputSampleRate)
+        override;
 
     /**
      * Get category metadata about a plugin (without instantiating it).
      */
-    virtual QString getPluginCategory(QString identifier);
+    virtual QString getPluginCategory(QString identifier) override;
 
 protected:
     QMutex m_mutex;
@@ -58,7 +59,8 @@
     friend class PluginDeletionNotifyAdapter;
     void pluginDeleted(Vamp::Plugin *);
     std::map<Vamp::Plugin *, void *> m_handleMap;
-    
+
+    QString findPluginFile(QString soname, QString inDir = "");
     std::vector<QString> getPluginPath();
     void generateTaxonomy();
 };
--- a/plugin/PiperVampPluginFactory.cpp	Fri Oct 21 14:51:22 2016 +0100
+++ b/plugin/PiperVampPluginFactory.cpp	Fri Oct 21 16:24:30 2016 +0100
@@ -32,6 +32,7 @@
 #include <QFile>
 #include <QFileInfo>
 #include <QTextStream>
+#include <QCoreApplication>
 
 #include <iostream>
 
@@ -45,19 +46,46 @@
 //#define DEBUG_PLUGIN_SCAN_AND_INSTANTIATE 1
 
 PiperVampPluginFactory::PiperVampPluginFactory() :
-    m_serverName("piper-cpp/bin/piper-vamp-server") //!!!
+    // No server unless we find one - don't run arbitrary stuff from the path:
+    m_serverName()
 {
+    // Server must exist either in the same directory as this one or
+    // (preferably) a subdirectory called "piper-bin".
+    //!!! todo: merge this with plugin scan checker thingy used in main.cpp?
+    QString myDir = QCoreApplication::applicationDirPath();
+    QString name = "piper-vamp-server";
+    QString path = myDir + "/piper-bin/" + name;
+    QString suffix = "";
+#ifdef _WIN32
+    suffix = ".exe";
+#endif
+    if (!QFile(path + suffix).exists()) {
+        cerr << "NOTE: Piper Vamp server not found at " << (path + suffix)
+             << ", trying in my own directory" << endl;
+        path = myDir + "/" + name;
+    }
+    if (!QFile(path + suffix).exists()) {
+        cerr << "NOTE: Piper Vamp server not found at " << (path + suffix)
+             << endl;
+    } else {
+        m_serverName = (path + suffix).toStdString();
+    }
 }
 
 vector<QString>
-PiperVampPluginFactory::getPluginIdentifiers()
+PiperVampPluginFactory::getPluginIdentifiers(QString &errorMessage)
 {
     Profiler profiler("PiperVampPluginFactory::getPluginIdentifiers");
 
     QMutexLocker locker(&m_mutex);
 
+    if (m_serverName == "") {
+        errorMessage = QObject::tr("External plugin host executable does not appear to be installed");
+        return {};
+    }
+    
     if (m_pluginData.empty()) {
-        populate();
+        populate(errorMessage);
     }
 
     vector<QString> rv;
@@ -111,9 +139,16 @@
 }
 
 void
-PiperVampPluginFactory::populate()
+PiperVampPluginFactory::populate(QString &errorMessage)
 {
+    if (m_serverName == "") return;
+
     piper_vamp::client::ProcessQtTransport transport(m_serverName);
+    if (!transport.isOK()) {
+        errorMessage = QObject::tr("Could not start external plugin host");
+        return;
+    }
+            
     piper_vamp::client::CapnpRRClient client(&transport);
     piper_vamp::ListResponse lr = client.listPluginData();
 
--- a/plugin/PiperVampPluginFactory.h	Fri Oct 21 14:51:22 2016 +0100
+++ b/plugin/PiperVampPluginFactory.h	Fri Oct 21 16:24:30 2016 +0100
@@ -35,7 +35,8 @@
 
     virtual ~PiperVampPluginFactory() { }
 
-    virtual std::vector<QString> getPluginIdentifiers() override;
+    virtual std::vector<QString> getPluginIdentifiers(QString &errorMessage)
+        override;
 
     virtual piper_vamp::PluginStaticData getPluginStaticData(QString identifier)
         override;
@@ -51,7 +52,7 @@
     std::string m_serverName;
     std::map<QString, piper_vamp::PluginStaticData> m_pluginData; // identifier -> data
     std::map<QString, QString> m_taxonomy; // identifier -> category string
-    void populate();
+    void populate(QString &errorMessage);
 };
 
 #endif
--- a/transform/TransformFactory.cpp	Fri Oct 21 14:51:22 2016 +0100
+++ b/transform/TransformFactory.cpp	Fri Oct 21 16:24:30 2016 +0100
@@ -405,8 +405,12 @@
 {
     FeatureExtractionPluginFactory *factory =
         FeatureExtractionPluginFactory::instance();
-    
-    std::vector<QString> plugs = factory->getPluginIdentifiers();
+
+    QString errorMessage;
+    std::vector<QString> plugs = factory->getPluginIdentifiers(errorMessage);
+    if (errorMessage != "") {
+        m_errorString = tr("Failed to list Vamp plugins: %1").arg(errorMessage);
+    }
     
     if (m_exiting) return;
 
--- a/transform/TransformFactory.h	Fri Oct 21 14:51:22 2016 +0100
+++ b/transform/TransformFactory.h	Fri Oct 21 16:24:30 2016 +0100
@@ -196,6 +196,10 @@
     void setParametersFromPluginConfigurationXml(Transform &transform,
                                                  QString xml);
     
+    QString getStartupFailureReport() const {
+        return m_errorString;
+    }
+    
 protected:
     typedef std::map<TransformId, TransformDescription> TransformDescriptionMap;
 
@@ -205,6 +209,8 @@
     TransformDescriptionMap m_uninstalledTransforms;
     bool m_uninstalledTransformsPopulated;
 
+    QString m_errorString;
+    
     void populateTransforms();
     void populateUninstalledTransforms();
     void populateFeatureExtractionPlugins(TransformDescriptionMap &);