Mercurial > hg > piper-cpp
diff vamp-client/ProcessQtTransport.h @ 100:bbb99f94e225
Serialisation, comments
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Fri, 14 Oct 2016 12:46:38 +0100 |
parents | 427c4c725085 |
children | 8c449824e08d |
line wrap: on
line diff
--- a/vamp-client/ProcessQtTransport.h Fri Oct 14 12:46:16 2016 +0100 +++ b/vamp-client/ProcessQtTransport.h Fri Oct 14 12:46:38 2016 +0100 @@ -6,12 +6,21 @@ #include <QProcess> #include <QString> +#include <QMutex> #include <iostream> namespace piper_vamp { namespace client { +/** + * A SynchronousTransport implementation that spawns a sub-process + * using Qt's QProcess abstraction and talks to it via stdin/stdout + * channels. Calls are completely serialized; the protocol only + * supports one call in process at a time, and therefore the transport + * only allows one at a time. This class is thread-safe because it + * serializes explicitly using a mutex. + */ class ProcessQtTransport : public SynchronousTransport { public: @@ -55,6 +64,8 @@ std::vector<char> call(const char *ptr, size_t size) override { + QMutexLocker locker(&m_mutex); + if (!m_completenessChecker) { throw std::logic_error("No completeness checker set on transport"); } @@ -88,6 +99,7 @@ private: MessageCompletenessChecker *m_completenessChecker; //!!! I don't own this (currently) QProcess *m_process; // I own this + QMutex m_mutex; }; }