comparison vamp-server/server.cpp @ 103:6fad5154778e

Add pid to server debug output
author Chris Cannam <c.cannam@qmul.ac.uk>
date Fri, 14 Oct 2016 16:23:36 +0100
parents 427c4c725085
children 491a4bc10a01
comparison
equal deleted inserted replaced
100:bbb99f94e225 103:6fad5154778e
11 #include <capnp/serialize.h> 11 #include <capnp/serialize.h>
12 12
13 #include <map> 13 #include <map>
14 #include <set> 14 #include <set>
15 15
16 #include <unistd.h> // getpid for logging
17
16 using namespace std; 18 using namespace std;
17 using namespace piper_vamp; 19 using namespace piper_vamp;
18 using namespace Vamp; 20 using namespace Vamp;
19 21
22 static int pid = getpid();
23
20 void usage() 24 void usage()
21 { 25 {
22 string myname = "piper-vamp-server"; 26 string myname = "piper-vamp-server";
23 cerr << "\n" << myname << 27 cerr << "\n" << myname <<
24 ": Load and run Vamp plugins in response to messages from stdin\n\n" 28 ": Load and run Vamp plugins in response to messages from stdin\n\n"
173 177
174 case RRType::Load: 178 case RRType::Load:
175 response.loadResponse = LoaderRequests().loadPlugin(request.loadRequest); 179 response.loadResponse = LoaderRequests().loadPlugin(request.loadRequest);
176 if (response.loadResponse.plugin != nullptr) { 180 if (response.loadResponse.plugin != nullptr) {
177 mapper.addPlugin(response.loadResponse.plugin); 181 mapper.addPlugin(response.loadResponse.plugin);
178 cerr << "loaded plugin, handle = " << mapper.pluginToHandle(response.loadResponse.plugin) << endl; 182 cerr << "piper-vamp-server " << pid << ": loaded plugin, handle = " << mapper.pluginToHandle(response.loadResponse.plugin) << endl;
179 response.success = true; 183 response.success = true;
180 } 184 }
181 break; 185 break;
182 186
183 case RRType::Configure: 187 case RRType::Configure:
255 } 259 }
256 260
257 return response; 261 return response;
258 } 262 }
259 263
260 int main(int argc, char **argv) 264 int main(int argc, char **)
261 { 265 {
262 if (argc != 1) { 266 if (argc != 1) {
263 usage(); 267 usage();
264 } 268 }
265 269
269 273
270 try { 274 try {
271 275
272 request = readRequestCapnp(); 276 request = readRequestCapnp();
273 277
274 cerr << "piper-vamp-server: request received, of type " 278 cerr << "piper-vamp-server " << pid << ": request received, of type "
275 << int(request.type) 279 << int(request.type)
276 << endl; 280 << endl;
277 281
278 // NotValid without an exception indicates EOF: 282 // NotValid without an exception indicates EOF:
279 if (request.type == RRType::NotValid) { 283 if (request.type == RRType::NotValid) {
280 cerr << "piper-vamp-server: eof reached, exiting" << endl; 284 cerr << "piper-vamp-server " << pid << ": eof reached, exiting" << endl;
281 break; 285 break;
282 } 286 }
283 287
284 RequestOrResponse response = handleRequest(request); 288 RequestOrResponse response = handleRequest(request);
285 response.id = request.id; 289 response.id = request.id;
286 290
287 cerr << "piper-vamp-server: request handled, writing response" 291 cerr << "piper-vamp-server " << pid << ": request handled, writing response"
288 << endl; 292 << endl;
289 293
290 writeResponseCapnp(response); 294 writeResponseCapnp(response);
291 295
292 cerr << "piper-vamp-server: response written" << endl; 296 cerr << "piper-vamp-server " << pid << ": response written" << endl;
293 297
294 if (request.type == RRType::Finish) { 298 if (request.type == RRType::Finish) {
295 auto h = mapper.pluginToHandle(request.finishRequest.plugin); 299 auto h = mapper.pluginToHandle(request.finishRequest.plugin);
296 cerr << "deleting the plugin with handle " << h << endl; 300 cerr << "piper-vamp-server " << pid << ": deleting the plugin with handle " << h << endl;
297 mapper.removePlugin(h); 301 mapper.removePlugin(h);
298 delete request.finishRequest.plugin; 302 delete request.finishRequest.plugin;
299 } 303 }
300 304
301 } catch (std::exception &e) { 305 } catch (std::exception &e) {
302 306
303 cerr << "piper-vamp-server: error: " << e.what() << endl; 307 cerr << "piper-vamp-server " << pid << ": error: " << e.what() << endl;
304 308
305 writeExceptionCapnp(e, request.type); 309 writeExceptionCapnp(e, request.type);
306 310
307 exit(1); 311 exit(1);
308 } 312 }