changeset 1247:8f076d02569a piper

Make SVDEBUG always write to a log file -- formerly this was disabled in NDEBUG builds. I think there's little use to that, it just means that we keep adding more cerr debug output because we aren't getting the log we need. And SVDEBUG logging is not usually used in tight loops, I don't think the performance overhead is too serious. Also update the About box.
author Chris Cannam
date Thu, 03 Nov 2016 14:57:00 +0000
parents 75aefcc9f07d
children 58dd6a6fe414
files base/Debug.cpp base/Debug.h base/ResourceFinder.cpp plugin/NativeVampPluginFactory.cpp plugin/PiperVampPluginFactory.cpp plugin/PluginScan.cpp
diffstat 6 files changed, 44 insertions(+), 59 deletions(-) [+]
line wrap: on
line diff
--- a/base/Debug.cpp	Thu Nov 03 14:14:09 2016 +0000
+++ b/base/Debug.cpp	Thu Nov 03 14:57:00 2016 +0000
@@ -21,7 +21,7 @@
 #include <QUrl>
 #include <QCoreApplication>
 
-#ifndef NDEBUG
+#include <stdexcept>
 
 static SVDebug *debug = 0;
 static QMutex mutex;
@@ -40,6 +40,11 @@
     m_ok(false),
     m_eol(false)
 {
+    if (qApp->applicationName() == "") {
+        cerr << "ERROR: Can't use SVDEBUG before setting application name" << endl;
+        throw std::logic_error("Can't use SVDEBUG before setting application name");
+    }
+    
     QString pfx = ResourceFinder().getUserResourcePrefix();
     QDir logdir(QString("%1/%2").arg(pfx).arg("log"));
 
@@ -76,8 +81,6 @@
     return dbg;
 }
 
-#endif
-
 std::ostream &
 operator<<(std::ostream &target, const QString &str)
 {
--- a/base/Debug.h	Thu Nov 03 14:14:09 2016 +0000
+++ b/base/Debug.h	Thu Nov 03 14:57:00 2016 +0000
@@ -36,8 +36,6 @@
 using std::cerr;
 using std::endl;
 
-#ifndef NDEBUG
-
 class SVDebug {
 public:
     SVDebug();
@@ -72,23 +70,5 @@
 
 #define SVDEBUG getSVDebug()
 
-#else
-
-class NoDebug
-{
-public:
-    inline NoDebug() {}
-    inline ~NoDebug(){}
-
-    template <typename T>
-    inline NoDebug &operator<<(const T &) { return *this; }
-
-    inline NoDebug &operator<<(QTextStreamFunction) { return *this; }
-};
-
-#define SVDEBUG NoDebug()
-
-#endif /* !NDEBUG */
-
 #endif /* !_DEBUG_H_ */
 
--- a/base/ResourceFinder.cpp	Thu Nov 03 14:14:09 2016 +0000
+++ b/base/ResourceFinder.cpp	Thu Nov 03 14:57:00 2016 +0000
@@ -33,6 +33,7 @@
 
 #include <cstdlib>
 #include <iostream>
+#include <stdexcept>
 
 /**
    Resource files may be found in three places:
@@ -126,6 +127,11 @@
 static QString
 getNewStyleUserResourcePrefix()
 {
+    if (qApp->applicationName() == "") {
+        cerr << "ERROR: Can't use ResourceFinder before setting application name" << endl;
+        throw std::logic_error("Can't use ResourceFinder before setting application name");
+    }
+
 #if QT_VERSION >= 0x050000
     // This is expected to be much more reliable than
     // getOldStyleUserResourcePrefix(), but it returns a different
@@ -133,7 +139,7 @@
     // fair enough). Hence migrateOldStyleResources() which moves
     // across any resources found in the old-style path the first time
     // we look for the new-style one
-    return QStandardPaths::writableLocation(QStandardPaths::DataLocation);
+    return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
 #else
     return getOldStyleUserResourcePrefix();
 #endif
--- a/plugin/NativeVampPluginFactory.cpp	Thu Nov 03 14:14:09 2016 +0000
+++ b/plugin/NativeVampPluginFactory.cpp	Thu Nov 03 14:57:00 2016 +0000
@@ -91,7 +91,7 @@
         void *libraryHandle = DLOPEN(soname, RTLD_LAZY | RTLD_LOCAL);
             
         if (!libraryHandle) {
-            cerr << "WARNING: NativeVampPluginFactory::getPluginIdentifiers: Failed to load library " << soname << ": " << DLERROR() << endl;
+            SVDEBUG << "WARNING: NativeVampPluginFactory::getPluginIdentifiers: Failed to load library " << soname << ": " << DLERROR() << endl;
             continue;
         }
 
@@ -99,9 +99,9 @@
             DLSYM(libraryHandle, "vampGetPluginDescriptor");
 
         if (!fn) {
-            cerr << "WARNING: NativeVampPluginFactory::getPluginIdentifiers: No descriptor function in " << soname << endl;
+            SVDEBUG << "WARNING: NativeVampPluginFactory::getPluginIdentifiers: No descriptor function in " << soname << endl;
             if (DLCLOSE(libraryHandle) != 0) {
-                cerr << "WARNING: NativeVampPluginFactory::getPluginIdentifiers: Failed to unload library " << soname << endl;
+                SVDEBUG << "WARNING: NativeVampPluginFactory::getPluginIdentifiers: Failed to unload library " << soname << endl;
             }
             continue;
         }
@@ -119,13 +119,13 @@
         while ((descriptor = fn(VAMP_API_VERSION, index))) {
 
             if (known.find(descriptor->identifier) != known.end()) {
-                cerr << "WARNING: NativeVampPluginFactory::getPluginIdentifiers: Plugin library "
+                SVDEBUG << "WARNING: NativeVampPluginFactory::getPluginIdentifiers: Plugin library "
                      << soname
                      << " returns the same plugin identifier \""
                      << descriptor->identifier << "\" at indices "
                      << known[descriptor->identifier] << " and "
                      << index << endl;
-                    cerr << "NativeVampPluginFactory::getPluginIdentifiers: Avoiding this library (obsolete API?)" << endl;
+                    SVDEBUG << "NativeVampPluginFactory::getPluginIdentifiers: Avoiding this library (obsolete API?)" << endl;
                 ok = false;
                 break;
             } else {
@@ -152,7 +152,7 @@
         }
             
         if (DLCLOSE(libraryHandle) != 0) {
-            cerr << "WARNING: NativeVampPluginFactory::getPluginIdentifiers: Failed to unload library " << soname << endl;
+            SVDEBUG << "WARNING: NativeVampPluginFactory::getPluginIdentifiers: Failed to unload library " << soname << endl;
         }
     }
 
@@ -273,7 +273,7 @@
     QString found = findPluginFile(soname);
 
     if (found == "") {
-        cerr << "NativeVampPluginFactory::instantiatePlugin: Failed to find library file " << soname << endl;
+        SVDEBUG << "NativeVampPluginFactory::instantiatePlugin: Failed to find library file " << soname << endl;
         return 0;
     } else if (found != soname) {
 
@@ -289,7 +289,7 @@
     void *libraryHandle = DLOPEN(soname, RTLD_LAZY | RTLD_LOCAL);
             
     if (!libraryHandle) {
-        cerr << "NativeVampPluginFactory::instantiatePlugin: Failed to load library " << soname << ": " << DLERROR() << endl;
+        SVDEBUG << "NativeVampPluginFactory::instantiatePlugin: Failed to load library " << soname << ": " << DLERROR() << endl;
         return 0;
     }
 
@@ -297,7 +297,7 @@
         DLSYM(libraryHandle, "vampGetPluginDescriptor");
     
     if (!fn) {
-        cerr << "NativeVampPluginFactory::instantiatePlugin: No descriptor function in " << soname << endl;
+        SVDEBUG << "NativeVampPluginFactory::instantiatePlugin: No descriptor function in " << soname << endl;
         goto done;
     }
 
@@ -307,7 +307,7 @@
     }
 
     if (!descriptor) {
-        cerr << "NativeVampPluginFactory::instantiatePlugin: Failed to find plugin \"" << label << "\" in library " << soname << endl;
+        SVDEBUG << "NativeVampPluginFactory::instantiatePlugin: Failed to find plugin \"" << label << "\" in library " << soname << endl;
         goto done;
     }
 
@@ -325,7 +325,7 @@
 done:
     if (!rv) {
         if (DLCLOSE(libraryHandle) != 0) {
-            cerr << "WARNING: NativeVampPluginFactory::instantiatePlugin: Failed to unload library " << soname << endl;
+            SVDEBUG << "WARNING: NativeVampPluginFactory::instantiatePlugin: Failed to unload library " << soname << endl;
         }
     }
 
--- a/plugin/PiperVampPluginFactory.cpp	Thu Nov 03 14:14:09 2016 +0000
+++ b/plugin/PiperVampPluginFactory.cpp	Thu Nov 03 14:57:00 2016 +0000
@@ -54,15 +54,15 @@
     m_servers = hep.getHelperExecutables(serverName);
 
     for (auto n: m_servers) {
-        cerr << "NOTE: PiperVampPluginFactory: Found server: "
-             << n.executable << endl;
+        SVDEBUG << "NOTE: PiperVampPluginFactory: Found server: "
+                << n.executable << endl;
     }
     
     if (m_servers.empty()) {
-        cerr << "NOTE: No Piper Vamp servers found in installation;"
-             << " found none of the following:" << endl;
+        SVDEBUG << "NOTE: No Piper Vamp servers found in installation;"
+                << " found none of the following:" << endl;
         for (auto d: hep.getHelperCandidatePaths(serverName)) {
-            cerr << "NOTE: " << d << endl;
+            SVDEBUG << "NOTE: " << d << endl;
         }
     }
 }
@@ -100,6 +100,7 @@
 
     if (m_origins.find(identifier) == m_origins.end()) {
         cerr << "ERROR: No known server for identifier " << identifier << endl;
+        SVDEBUG << "ERROR: No known server for identifier " << identifier << endl;
         return 0;
     }
     
@@ -170,22 +171,22 @@
     for (const auto &c: candidateLibraries) {
         if (c.helperTag == tag) {
             string soname = QFileInfo(c.libraryPath).baseName().toStdString();
-            cerr << "INFO: For tag \"" << tag << "\" giving library " << soname << endl;
+            SVDEBUG << "INFO: For tag \"" << tag << "\" giving library " << soname << endl;
             from.push_back(soname);
         }
     }
 
     if (from.empty()) {
-        cerr << "PiperVampPluginFactory: No candidate libraries for tag \""
+        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)
-            cerr << ", skipping" << endl;
+            SVDEBUG << ", skipping" << endl;
             return;
         } else {
-            cerr << ", but it seems the scan failed, so bumbling on anyway" << endl;
+            SVDEBUG << ", but it seems the scan failed, so bumbling on anyway" << endl;
         }
     }
     
@@ -210,8 +211,8 @@
         return;
     }
 
-    cerr << "PiperVampPluginFactory: server \"" << executable << "\" lists "
-         << lr.available.size() << " plugin(s)" << endl;
+    SVDEBUG << "PiperVampPluginFactory: server \"" << executable << "\" lists "
+            << lr.available.size() << " plugin(s)" << endl;
 
     for (const auto &pd: lr.available) {
         
--- a/plugin/PluginScan.cpp	Thu Nov 03 14:14:09 2016 +0000
+++ b/plugin/PluginScan.cpp	Thu Nov 03 14:57:00 2016 +0000
@@ -25,15 +25,10 @@
 
 using std::string;
 
-//#define DEBUG_PLUGIN_SCAN 1
-
 class PluginScan::Logger : public PluginCandidates::LogCallback
 {
 protected:
     void log(std::string message) {
-#ifdef DEBUG_PLUGIN_SCAN
-        cerr << "PluginScan: " << message;
-#endif
         SVDEBUG << "PluginScan: " << message;
     }
 };
@@ -74,14 +69,14 @@
     clear();
 
     for (auto p: helpers) {
-        cerr << "NOTE: PluginScan: Found helper: " << p.executable << endl;
+        SVDEBUG << "NOTE: PluginScan: Found helper: " << p.executable << endl;
     }
     
     if (helpers.empty()) {
-        cerr << "NOTE: No plugin checker helpers found in installation;"
+        SVDEBUG << "NOTE: No plugin checker helpers found in installation;"
              << " found none of the following:" << endl;
         for (auto d: hep.getHelperCandidatePaths(helperName)) {
-            cerr << "NOTE: " << d << endl;
+            SVDEBUG << "NOTE: " << d << endl;
         }
     }
 
@@ -90,14 +85,14 @@
             KnownPlugins *kp = new KnownPlugins
                 (p.executable.toStdString(), m_logger);
             if (m_kp.find(p.tag) != m_kp.end()) {
-                cerr << "WARNING: PluginScan::scan: Duplicate tag " << p.tag
+                SVDEBUG << "WARNING: PluginScan::scan: Duplicate tag " << p.tag
                      << " for helpers" << endl;
                 continue;
             }
             m_kp[p.tag] = kp;
             m_succeeded = true;
         } catch (const std::exception &e) {
-            cerr << "ERROR: PluginScan::scan: " << e.what()
+            SVDEBUG << "ERROR: PluginScan::scan: " << e.what()
                  << " (with helper path = " << p.executable << ")" << endl;
         }
     }
@@ -141,9 +136,9 @@
         
         auto c = kp->getCandidateLibrariesFor(kpt);
 
-        std::cerr << "PluginScan: helper \"" << kp->getHelperExecutableName()
-                  << "\" likes " << c.size() << " libraries of type "
-                  << kp->getTagFor(kpt) << std::endl;
+        SVDEBUG << "PluginScan: helper \"" << kp->getHelperExecutableName()
+                << "\" likes " << c.size() << " libraries of type "
+                << kp->getTagFor(kpt) << endl;
 
         for (auto s: c) {
             candidates.push_back({ s.c_str(), rec.first });