Mercurial > hg > piper-cpp
comparison vamp-client/ProcessQtTransport.h @ 125:ea06fae1567c
Rename server to simple-server, and add some more description in usage
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Fri, 28 Oct 2016 11:08:17 +0100 |
parents | 4ff643c1eccc |
children | 2004ec2b653e |
comparison
equal
deleted
inserted
replaced
124:4ff643c1eccc | 125:ea06fae1567c |
---|---|
52 /** | 52 /** |
53 * A SynchronousTransport implementation that spawns a sub-process | 53 * A SynchronousTransport implementation that spawns a sub-process |
54 * using Qt's QProcess abstraction and talks to it via stdin/stdout | 54 * using Qt's QProcess abstraction and talks to it via stdin/stdout |
55 * channels. Calls are completely serialized; the protocol only | 55 * channels. Calls are completely serialized; the protocol only |
56 * supports one call in process at a time, and therefore the transport | 56 * supports one call in process at a time, and therefore the transport |
57 * only allows one at a time. This class is thread-safe because it | 57 * only allows one at a time. |
58 * serializes explicitly using a mutex. | 58 * |
59 * This class is thread-safe, but in practice you can only use it from | |
60 * within a single thread, because the underlying QProcess does not | |
61 * support switching threads. | |
59 */ | 62 */ |
60 class ProcessQtTransport : public SynchronousTransport | 63 class ProcessQtTransport : public SynchronousTransport |
61 { | 64 { |
62 public: | 65 public: |
63 ProcessQtTransport(std::string processName, std::string formatArg) : | 66 ProcessQtTransport(std::string processName, std::string formatArg) : |
127 | 130 |
128 #ifdef DEBUG_TRANSPORT | 131 #ifdef DEBUG_TRANSPORT |
129 std::cerr << "writing " << size << " bytes to server" << std::endl; | 132 std::cerr << "writing " << size << " bytes to server" << std::endl; |
130 #endif | 133 #endif |
131 m_process->write(ptr, size); | 134 m_process->write(ptr, size); |
135 m_process->waitForBytesWritten(1000); | |
132 | 136 |
133 std::vector<char> buffer; | 137 std::vector<char> buffer; |
134 bool complete = false; | 138 bool complete = false; |
135 | 139 |
136 while (!complete) { | 140 while (!complete) { |
140 if (!byteCount) { | 144 if (!byteCount) { |
141 #ifdef DEBUG_TRANSPORT | 145 #ifdef DEBUG_TRANSPORT |
142 std::cerr << "waiting for data from server..." << std::endl; | 146 std::cerr << "waiting for data from server..." << std::endl; |
143 #endif | 147 #endif |
144 m_process->waitForReadyRead(1000); | 148 m_process->waitForReadyRead(1000); |
149 | |
145 if (m_process->state() == QProcess::NotRunning) { | 150 if (m_process->state() == QProcess::NotRunning) { |
146 QProcess::ProcessError err = m_process->error(); | 151 QProcess::ProcessError err = m_process->error(); |
147 if (err == QProcess::Crashed) { | 152 if (err == QProcess::Crashed) { |
148 std::cerr << "Server crashed during request" << std::endl; | 153 std::cerr << "Server crashed during request" << std::endl; |
149 } else { | 154 } else { |