Mercurial > hg > piper-cpp
changeset 167:4a37daf5f8b4
Add a failed state to the plugin stub, to prevent it making any further
requests after (for example) a process has timed out
author | Chris Cannam <cannam@all-day-breakfast.com> |
---|---|
date | Tue, 31 Jan 2017 11:08:31 +0000 |
parents | 49f606e3653e |
children | 718dd5404855 f13dc1db2229 |
files | vamp-client/PluginStub.h |
diffstat | 1 files changed, 40 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/vamp-client/PluginStub.h Sat Jan 21 12:21:13 2017 +0000 +++ b/vamp-client/PluginStub.h Tue Jan 31 11:08:31 2017 +0000 @@ -42,9 +42,10 @@ #include "vamp-support/PluginStaticData.h" #include "vamp-support/PluginConfiguration.h" +#include "PluginClient.h" + #include <cstdint> - -#include "PluginClient.h" +#include <iostream> namespace piper_vamp { namespace client { @@ -52,7 +53,7 @@ class PluginStub : public Vamp::Plugin { enum State { - Loaded, Configured, Finished + Loaded, Configured, Finished, Failed }; public: @@ -73,8 +74,13 @@ { } virtual ~PluginStub() { - if (m_state != Finished) { - (void)m_client->finish(this); + if (m_state != Finished && m_state != Failed) { + try { + (void)m_client->finish(this); + } catch (const std::exception &e) { + // Finish can throw, but our destructor must not + std::cerr << "WARNING: PluginStub::~PluginStub: caught exception from finish(): " << e.what() << std::endl; + } } } @@ -115,7 +121,11 @@ } virtual void setParameter(std::string name, float value) { + if (m_state == Failed) { + throw std::logic_error("Plugin is in failed state"); + } if (m_state != Loaded) { + m_state = Failed; throw std::logic_error("Can't set parameter after plugin initialised"); } m_config.parameterValues[name] = value; @@ -130,7 +140,11 @@ } virtual void selectProgram(std::string program) { + if (m_state == Failed) { + throw std::logic_error("Plugin is in failed state"); + } if (m_state != Loaded) { + m_state = Failed; throw std::logic_error("Can't select program after plugin initialised"); } m_config.currentProgram = program; @@ -140,7 +154,11 @@ size_t stepSize, size_t blockSize) { + if (m_state == Failed) { + throw std::logic_error("Plugin is in failed state"); + } if (m_state != Loaded) { + m_state = Failed; throw std::logic_error("Plugin has already been initialised"); } @@ -160,6 +178,9 @@ virtual void reset() { + if (m_state == Failed) { + throw std::logic_error("Plugin is in failed state"); + } if (m_state == Loaded) { // reset is a no-op if the plugin hasn't been initialised yet return; @@ -191,6 +212,10 @@ } virtual OutputList getOutputDescriptors() const { + + if (m_state == Failed) { + throw std::logic_error("Plugin is in failed state"); + } if (m_state == Configured) { return m_outputs; } @@ -214,10 +239,15 @@ virtual FeatureSet process(const float *const *inputBuffers, Vamp::RealTime timestamp) { + if (m_state == Failed) { + throw std::logic_error("Plugin is in failed state"); + } if (m_state == Loaded) { + m_state = Failed; throw std::logic_error("Plugin has not been initialised"); } if (m_state == Finished) { + m_state = Failed; throw std::logic_error("Plugin has already been disposed of"); } @@ -234,10 +264,15 @@ virtual FeatureSet getRemainingFeatures() { + if (m_state == Failed) { + throw std::logic_error("Plugin is in failed state"); + } if (m_state == Loaded) { + m_state = Failed; throw std::logic_error("Plugin has not been configured"); } if (m_state == Finished) { + m_state = Failed; throw std::logic_error("Plugin has already been disposed of"); }