changeset 100:bbb99f94e225

Serialisation, comments
author Chris Cannam <c.cannam@qmul.ac.uk>
date Fri, 14 Oct 2016 12:46:38 +0100
parents b2ec891c22b9
children 8c449824e08d 6fad5154778e
files vamp-client/CapnpRRClient.h vamp-client/ProcessQtTransport.h
diffstat 2 files changed, 20 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/vamp-client/CapnpRRClient.h	Fri Oct 14 12:46:16 2016 +0100
+++ b/vamp-client/CapnpRRClient.h	Fri Oct 14 12:46:38 2016 +0100
@@ -15,6 +15,14 @@
 namespace piper_vamp {
 namespace client {
 
+/**
+ * Client for a request-response Piper server, i.e. using the
+ * RpcRequest/RpcResponse structures with a single process call rather
+ * than having individual RPC methods, with a synchronous transport
+ * such as a subprocess pipe arrangement. Only one request can be
+ * handled at a time. This class is thread-safe if and only if it is
+ * constructed with a thread-safe SynchronousTransport implementation.
+ */
 class CapnpRRClient : public PluginClient,
 		      public Loader
 {
--- 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;
 };
 
 }