changeset 93:fbce91785d35

Having a class called PipedXX is too confusing with all the Piper classes; give up and rename it
author Chris Cannam <c.cannam@qmul.ac.uk>
date Thu, 13 Oct 2016 12:07:41 +0100
parents 21f8af53eaf0
children a660dca988f8
files vamp-client/Makefile vamp-client/PipedQProcessTransport.h vamp-client/PiperQProcessTransport.h vamp-client/client.cpp vamp-client/client.pro
diffstat 5 files changed, 100 insertions(+), 100 deletions(-) [+]
line wrap: on
line diff
--- a/vamp-client/Makefile	Thu Oct 13 12:02:44 2016 +0100
+++ b/vamp-client/Makefile	Thu Oct 13 12:07:41 2016 +0100
@@ -205,7 +205,7 @@
 		/usr/lib/qt/mkspecs/features/testcase_targets.prf \
 		/usr/lib/qt/mkspecs/features/yacc.prf \
 		/usr/lib/qt/mkspecs/features/lex.prf \
-		client.pro PipedQProcessTransport.h \
+		client.pro PiperQProcessTransport.h \
 		PiperCapnpClient.h \
 		PiperClient.h \
 		PiperPluginStub.h \
@@ -547,7 +547,7 @@
 distdir: FORCE
 	@test -d $(DISTDIR) || mkdir -p $(DISTDIR)
 	$(COPY_FILE) --parents $(DIST) $(DISTDIR)/
-	$(COPY_FILE) --parents PipedQProcessTransport.h PiperCapnpClient.h PiperClient.h PiperPluginStub.h SynchronousTransport.h $(DISTDIR)/
+	$(COPY_FILE) --parents PiperQProcessTransport.h PiperCapnpClient.h PiperClient.h PiperPluginStub.h SynchronousTransport.h $(DISTDIR)/
 	$(COPY_FILE) --parents client.cpp ../vamp-capnp/piper.capnp.c++ $(DISTDIR)/
 
 
@@ -588,7 +588,7 @@
 
 ####### Compile
 
-../o/client.o: client.cpp PipedQProcessTransport.h \
+../o/client.o: client.cpp PiperQProcessTransport.h \
 		SynchronousTransport.h \
 		PiperCapnpClient.h \
 		PiperClient.h \
--- a/vamp-client/PipedQProcessTransport.h	Thu Oct 13 12:02:44 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,94 +0,0 @@
-
-#ifndef PIPER_PIPED_QPROCESS_TRANSPORT_H
-#define PIPER_PIPED_QPROCESS_TRANSPORT_H
-
-#include "SynchronousTransport.h"
-
-#include <QProcess>
-#include <QString>
-
-#include <iostream>
-
-namespace piper { //!!! change
-
-class PipedQProcessTransport : public SynchronousTransport
-{
-public:
-    PipedQProcessTransport(QString processName) :
-        m_completenessChecker(0) {
-        m_process = new QProcess();
-        m_process->setReadChannel(QProcess::StandardOutput);
-        m_process->setProcessChannelMode(QProcess::ForwardedErrorChannel);
-        m_process->start(processName);
-        if (!m_process->waitForStarted()) {
-            std::cerr << "server failed to start" << std::endl;
-            delete m_process;
-            m_process = nullptr;
-        }
-    }
-
-    ~PipedQProcessTransport() {
-        if (m_process) {
-            if (m_process->state() != QProcess::NotRunning) {
-		m_process->closeWriteChannel();
-                m_process->waitForFinished(200);
-                m_process->close();
-                m_process->waitForFinished();
-                std::cerr << "server exited" << std::endl;
-            }
-            delete m_process;
-        }
-    }
-
-    void
-    setCompletenessChecker(MessageCompletenessChecker *checker) {
-        //!!! ownership?
-        m_completenessChecker = checker;
-    }
-    
-    bool
-    isOK() const override {
-        return m_process != nullptr;
-    }
-    
-    std::vector<char>
-    call(const char *ptr, size_t size) override {
-
-        if (!m_completenessChecker) {
-            throw std::logic_error("No completeness checker set on transport");
-        }
-        
-        m_process->write(ptr, size);
-        
-        std::vector<char> buffer;
-        bool complete = false;
-        
-        while (!complete) {
-
-            m_process->waitForReadyRead(1000);
-            qint64 byteCount = m_process->bytesAvailable();
-
-            if (!byteCount) {
-                if (m_process->state() == QProcess::NotRunning) {
-                    std::cerr << "ERROR: Subprocess exited: Load failed" << std::endl;
-                    throw std::runtime_error("Piper server exited unexpectedly");
-                }
-            } else {
-                size_t formerSize = buffer.size();
-                buffer.resize(formerSize + byteCount);
-                m_process->read(buffer.data() + formerSize, byteCount);
-                complete = m_completenessChecker->isComplete(buffer);
-            }
-        }
-
-        return buffer;
-    }
-    
-private:
-    MessageCompletenessChecker *m_completenessChecker; //!!! I don't own this (currently)
-    QProcess *m_process; // I own this
-};
-
-}
-
-#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vamp-client/PiperQProcessTransport.h	Thu Oct 13 12:07:41 2016 +0100
@@ -0,0 +1,94 @@
+
+#ifndef PIPER_QPROCESS_TRANSPORT_H
+#define PIPER_QPROCESS_TRANSPORT_H
+
+#include "SynchronousTransport.h"
+
+#include <QProcess>
+#include <QString>
+
+#include <iostream>
+
+namespace piper { //!!! change
+
+class PiperQProcessTransport : public SynchronousTransport
+{
+public:
+    PiperQProcessTransport(QString processName) :
+        m_completenessChecker(0) {
+        m_process = new QProcess();
+        m_process->setReadChannel(QProcess::StandardOutput);
+        m_process->setProcessChannelMode(QProcess::ForwardedErrorChannel);
+        m_process->start(processName);
+        if (!m_process->waitForStarted()) {
+            std::cerr << "server failed to start" << std::endl;
+            delete m_process;
+            m_process = nullptr;
+        }
+    }
+
+    ~PiperQProcessTransport() {
+        if (m_process) {
+            if (m_process->state() != QProcess::NotRunning) {
+		m_process->closeWriteChannel();
+                m_process->waitForFinished(200);
+                m_process->close();
+                m_process->waitForFinished();
+                std::cerr << "server exited" << std::endl;
+            }
+            delete m_process;
+        }
+    }
+
+    void
+    setCompletenessChecker(MessageCompletenessChecker *checker) {
+        //!!! ownership?
+        m_completenessChecker = checker;
+    }
+    
+    bool
+    isOK() const override {
+        return m_process != nullptr;
+    }
+    
+    std::vector<char>
+    call(const char *ptr, size_t size) override {
+
+        if (!m_completenessChecker) {
+            throw std::logic_error("No completeness checker set on transport");
+        }
+        
+        m_process->write(ptr, size);
+        
+        std::vector<char> buffer;
+        bool complete = false;
+        
+        while (!complete) {
+
+            m_process->waitForReadyRead(1000);
+            qint64 byteCount = m_process->bytesAvailable();
+
+            if (!byteCount) {
+                if (m_process->state() == QProcess::NotRunning) {
+                    std::cerr << "ERROR: Subprocess exited: Load failed" << std::endl;
+                    throw std::runtime_error("Piper server exited unexpectedly");
+                }
+            } else {
+                size_t formerSize = buffer.size();
+                buffer.resize(formerSize + byteCount);
+                m_process->read(buffer.data() + formerSize, byteCount);
+                complete = m_completenessChecker->isComplete(buffer);
+            }
+        }
+
+        return buffer;
+    }
+    
+private:
+    MessageCompletenessChecker *m_completenessChecker; //!!! I don't own this (currently)
+    QProcess *m_process; // I own this
+};
+
+}
+
+#endif
--- a/vamp-client/client.cpp	Thu Oct 13 12:02:44 2016 +0100
+++ b/vamp-client/client.cpp	Thu Oct 13 12:07:41 2016 +0100
@@ -1,5 +1,5 @@
 
-#include "PipedQProcessTransport.h"
+#include "PiperQProcessTransport.h"
 #include "PiperCapnpClient.h"
 
 #include <stdexcept>
@@ -9,7 +9,7 @@
 
 int main(int, char **)
 {
-    piper::PipedQProcessTransport transport("../bin/piper-vamp-server");
+    piper::PiperQProcessTransport transport("../bin/piper-vamp-server");
     piper::PiperCapnpClient client(&transport);
     
     Vamp::Plugin *plugin = client.load("vamp-example-plugins:zerocrossing", 16, 0);
--- a/vamp-client/client.pro	Thu Oct 13 12:02:44 2016 +0100
+++ b/vamp-client/client.pro	Thu Oct 13 12:07:41 2016 +0100
@@ -29,7 +29,7 @@
         ../vamp-capnp/piper.capnp.c++
         
 HEADERS += \
-        PipedQProcessTransport.h \
+        PiperQProcessTransport.h \
         PiperCapnpClient.h \
         PiperClient.h \
         PiperPluginStub.h \