diff vamp-client/AutoPlugin.h @ 134:3dcf0394971d

Debug output improvements, and make the checker actually attempt to call the descriptor function for known plugin types
author Chris Cannam <c.cannam@qmul.ac.uk>
date Wed, 16 Nov 2016 16:12:42 +0000
parents 56e537a7bb99
children
line wrap: on
line diff
--- a/vamp-client/AutoPlugin.h	Fri Nov 04 10:43:49 2016 +0000
+++ b/vamp-client/AutoPlugin.h	Wed Nov 16 16:12:42 2016 +0000
@@ -50,10 +50,12 @@
     AutoPlugin(std::string serverName,
                std::string pluginKey,
                float inputSampleRate,
-               int adapterFlags) :
+               int adapterFlags,
+               LogCallback *logger) : // logger may be nullptr for cerr
         Vamp::Plugin(inputSampleRate),
-        m_transport(serverName, "capnp"),
-        m_client(&m_transport)
+        m_logger(logger),
+        m_transport(serverName, "capnp", logger),
+        m_client(&m_transport, logger)
     {
         LoadRequest req;
         req.pluginKey = pluginKey;
@@ -63,7 +65,7 @@
             LoadResponse resp = m_client.loadPlugin(req);
             m_plugin = resp.plugin;
         } catch (ServerCrashed c) {
-            std::cerr << c.what() << std::endl;
+            log(std::string("AutoPlugin: Server crashed: ") + c.what());
             m_plugin = 0;
         }
     }
@@ -168,16 +170,22 @@
     }
 
 private:
+    LogCallback *m_logger;
     ProcessQtTransport m_transport;
     CapnpRRClient m_client;
     Vamp::Plugin *m_plugin;
     Vamp::Plugin *getPlugin() const {
         if (!m_plugin) {
-            throw std::logic_error
-                ("Plugin load failed (should have called AutoPlugin::isOK)");
+            log("AutoPlugin: getPlugin() failed (caller should have called AutoPlugin::isOK)");
+            throw std::logic_error("Plugin load failed");
         }
         return m_plugin;
     }
+
+    void log(std::string message) const {
+        if (m_logger) m_logger->log(message);
+        else std::cerr << message << std::endl;
+    }
 };
 
 }