comparison vamp-client/qt/AutoPlugin.h @ 170:590b1a1fd955

More work on error and exception handling
author Chris Cannam <cannam@all-day-breakfast.com>
date Tue, 31 Jan 2017 14:53:24 +0000
parents 6ccb195d6de6
children 52322dde68ea
comparison
equal deleted inserted replaced
169:f13dc1db2229 170:590b1a1fd955
36 #ifndef PIPER_AUTO_PLUGIN_H 36 #ifndef PIPER_AUTO_PLUGIN_H
37 #define PIPER_AUTO_PLUGIN_H 37 #define PIPER_AUTO_PLUGIN_H
38 38
39 #include "ProcessQtTransport.h" 39 #include "ProcessQtTransport.h"
40 #include "../CapnpRRClient.h" 40 #include "../CapnpRRClient.h"
41 #include "../Exceptions.h"
41 42
42 #include <cstdint> 43 #include <cstdint>
43 44
44 namespace piper_vamp { 45 namespace piper_vamp {
45 namespace client { 46 namespace client {
46 47
48 /**
49 * This "plugin" make the Piper client abstraction behave like a local
50 * Vamp plugin, with its own server that lasts only for the lifetime
51 * of this plugin and serves only it.
52 *
53 * Note that any method may throw ServerCrashed, RequestTimedOut or
54 * ProtocolError exceptions.
55 */
47 class AutoPlugin : public Vamp::Plugin 56 class AutoPlugin : public Vamp::Plugin
48 { 57 {
49 public: 58 public:
50 AutoPlugin(std::string serverName, 59 AutoPlugin(std::string serverName,
51 std::string pluginKey, 60 std::string pluginKey,
127 } 136 }
128 137
129 virtual bool initialise(size_t inputChannels, 138 virtual bool initialise(size_t inputChannels,
130 size_t stepSize, 139 size_t stepSize,
131 size_t blockSize) { 140 size_t blockSize) {
132 return getPlugin()->initialise(inputChannels, stepSize, blockSize); 141 try {
142 return getPlugin()->initialise(inputChannels, stepSize, blockSize);
143 } catch (const ServiceError &e) {
144 // Sadly, the Vamp API has taught hosts to try to divine
145 // initialisation problems from a bool return value alone
146 log(std::string("AutoPlugin: initialise failed: ") + e.what());
147 return false;
148 }
133 } 149 }
134 150
135 virtual void reset() { 151 virtual void reset() {
136 getPlugin()->reset(); 152 getPlugin()->reset();
137 } 153 }