# HG changeset patch # User Chris Cannam # Date 1476356861 -3600 # Node ID fbce91785d35eb15c4fb6d8f1e0e6e3594b5f6a5 # Parent 21f8af53eaf0b0ea0f4073a9d1a3cf61a382b01d Having a class called PipedXX is too confusing with all the Piper classes; give up and rename it diff -r 21f8af53eaf0 -r fbce91785d35 vamp-client/Makefile --- 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 \ diff -r 21f8af53eaf0 -r fbce91785d35 vamp-client/PipedQProcessTransport.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 -#include - -#include - -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 - 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 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 diff -r 21f8af53eaf0 -r fbce91785d35 vamp-client/PiperQProcessTransport.h --- /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 +#include + +#include + +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 + 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 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 diff -r 21f8af53eaf0 -r fbce91785d35 vamp-client/client.cpp --- 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 @@ -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); diff -r 21f8af53eaf0 -r fbce91785d35 vamp-client/client.pro --- 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 \