comparison 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
comparison
equal deleted inserted replaced
99:b2ec891c22b9 100:bbb99f94e225
4 4
5 #include "SynchronousTransport.h" 5 #include "SynchronousTransport.h"
6 6
7 #include <QProcess> 7 #include <QProcess>
8 #include <QString> 8 #include <QString>
9 #include <QMutex>
9 10
10 #include <iostream> 11 #include <iostream>
11 12
12 namespace piper_vamp { 13 namespace piper_vamp {
13 namespace client { 14 namespace client {
14 15
16 /**
17 * A SynchronousTransport implementation that spawns a sub-process
18 * using Qt's QProcess abstraction and talks to it via stdin/stdout
19 * channels. Calls are completely serialized; the protocol only
20 * supports one call in process at a time, and therefore the transport
21 * only allows one at a time. This class is thread-safe because it
22 * serializes explicitly using a mutex.
23 */
15 class ProcessQtTransport : public SynchronousTransport 24 class ProcessQtTransport : public SynchronousTransport
16 { 25 {
17 public: 26 public:
18 ProcessQtTransport(QString processName) : 27 ProcessQtTransport(QString processName) :
19 m_completenessChecker(0) { 28 m_completenessChecker(0) {
53 } 62 }
54 63
55 std::vector<char> 64 std::vector<char>
56 call(const char *ptr, size_t size) override { 65 call(const char *ptr, size_t size) override {
57 66
67 QMutexLocker locker(&m_mutex);
68
58 if (!m_completenessChecker) { 69 if (!m_completenessChecker) {
59 throw std::logic_error("No completeness checker set on transport"); 70 throw std::logic_error("No completeness checker set on transport");
60 } 71 }
61 72
62 m_process->write(ptr, size); 73 m_process->write(ptr, size);
86 } 97 }
87 98
88 private: 99 private:
89 MessageCompletenessChecker *m_completenessChecker; //!!! I don't own this (currently) 100 MessageCompletenessChecker *m_completenessChecker; //!!! I don't own this (currently)
90 QProcess *m_process; // I own this 101 QProcess *m_process; // I own this
102 QMutex m_mutex;
91 }; 103 };
92 104
93 } 105 }
94 } 106 }
95 107