# HG changeset patch # User Chris Cannam # Date 1485860911 0 # Node ID 4a37daf5f8b48b92069d0453e8bafcd23cf5bcd3 # Parent 49f606e3653eba3877967898230f58a143e8ed0a Add a failed state to the plugin stub, to prevent it making any further requests after (for example) a process has timed out diff -r 49f606e3653e -r 4a37daf5f8b4 vamp-client/PluginStub.h --- 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 - -#include "PluginClient.h" +#include 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"); }