# HG changeset patch # User Chris Cannam # Date 1587638374 -3600 # Node ID 8ffb8985ae8fc8840968ac4372e8c02cb4e1961a # Parent b9422f3e63a41559ecea3da3e2d6a3a8980d81db Add ability to disown a wrapped plugin - making it possible to use the adapters in some situations involving managed pointers that didn't work previously diff -r b9422f3e63a4 -r 8ffb8985ae8f src/vamp-hostsdk/PluginWrapper.cpp --- a/src/vamp-hostsdk/PluginWrapper.cpp Wed Apr 22 14:23:51 2020 +0100 +++ b/src/vamp-hostsdk/PluginWrapper.cpp Thu Apr 23 11:39:34 2020 +0100 @@ -44,13 +44,22 @@ PluginWrapper::PluginWrapper(Plugin *plugin) : Plugin(plugin->getInputSampleRate()), - m_plugin(plugin) + m_plugin(plugin), + m_pluginIsOwned(true) { } PluginWrapper::~PluginWrapper() { - delete m_plugin; + if (m_pluginIsOwned) { + delete m_plugin; + } +} + +void +PluginWrapper::disownPlugin() +{ + m_pluginIsOwned = false; } bool diff -r b9422f3e63a4 -r 8ffb8985ae8f vamp-hostsdk/PluginBufferingAdapter.h --- a/vamp-hostsdk/PluginBufferingAdapter.h Wed Apr 22 14:23:51 2020 +0100 +++ b/vamp-hostsdk/PluginBufferingAdapter.h Thu Apr 23 11:39:34 2020 +0100 @@ -69,7 +69,8 @@ * * In other respects, the PluginBufferingAdapter behaves identically * to the plugin that it wraps. The wrapped plugin will be deleted - * when the wrapper is deleted. + * when the wrapper is deleted. If you wish to prevent this, call + * disownPlugin(). */ class PluginBufferingAdapter : public PluginWrapper @@ -78,7 +79,8 @@ /** * Construct a PluginBufferingAdapter wrapping the given plugin. * The adapter takes ownership of the plugin, which will be - * deleted when the adapter is deleted. + * deleted when the adapter is deleted. If you wish to prevent + * this, call disownPlugin(). */ PluginBufferingAdapter(Plugin *plugin); virtual ~PluginBufferingAdapter(); diff -r b9422f3e63a4 -r 8ffb8985ae8f vamp-hostsdk/PluginChannelAdapter.h --- a/vamp-hostsdk/PluginChannelAdapter.h Wed Apr 22 14:23:51 2020 +0100 +++ b/vamp-hostsdk/PluginChannelAdapter.h Thu Apr 23 11:39:34 2020 +0100 @@ -104,7 +104,7 @@ * In every respect other than its management of channels, the * PluginChannelAdapter behaves identically to the plugin that it * wraps. The wrapped plugin will be deleted when the wrapper is - * deleted. + * deleted. If you wish to prevent this, call disownPlugin(). * * \note This class was introduced in version 1.1 of the Vamp plugin SDK. */ @@ -115,7 +115,8 @@ /** * Construct a PluginChannelAdapter wrapping the given plugin. * The adapter takes ownership of the plugin, which will be - * deleted when the adapter is deleted. + * deleted when the adapter is deleted. If you wish to prevent + * this, call disownPlugin(). */ PluginChannelAdapter(Plugin *plugin); virtual ~PluginChannelAdapter(); diff -r b9422f3e63a4 -r 8ffb8985ae8f vamp-hostsdk/PluginInputDomainAdapter.h --- a/vamp-hostsdk/PluginInputDomainAdapter.h Wed Apr 22 14:23:51 2020 +0100 +++ b/vamp-hostsdk/PluginInputDomainAdapter.h Thu Apr 23 11:39:34 2020 +0100 @@ -79,7 +79,7 @@ * In every respect other than its input domain handling, the * PluginInputDomainAdapter behaves identically to the plugin that it * wraps. The wrapped plugin will be deleted when the wrapper is - * deleted. + * deleted. If you wish to prevent this, call disownPlugin(). * * \note This class was introduced in version 1.1 of the Vamp plugin SDK. */ @@ -90,7 +90,8 @@ /** * Construct a PluginInputDomainAdapter wrapping the given plugin. * The adapter takes ownership of the plugin, which will be - * deleted when the adapter is deleted. + * deleted when the adapter is deleted. If you wish to prevent + * this, call disownPlugin(). */ PluginInputDomainAdapter(Plugin *plugin); virtual ~PluginInputDomainAdapter(); diff -r b9422f3e63a4 -r 8ffb8985ae8f vamp-hostsdk/PluginSummarisingAdapter.h --- a/vamp-hostsdk/PluginSummarisingAdapter.h Wed Apr 22 14:23:51 2020 +0100 +++ b/vamp-hostsdk/PluginSummarisingAdapter.h Thu Apr 23 11:39:34 2020 +0100 @@ -89,7 +89,8 @@ /** * Construct a PluginSummarisingAdapter wrapping the given plugin. * The adapter takes ownership of the plugin, which will be - * deleted when the adapter is deleted. + * deleted when the adapter is deleted. If you wish to prevent + * this, call disownPlugin(). */ PluginSummarisingAdapter(Plugin *plugin); virtual ~PluginSummarisingAdapter(); diff -r b9422f3e63a4 -r 8ffb8985ae8f vamp-hostsdk/PluginWrapper.h --- a/vamp-hostsdk/PluginWrapper.h Wed Apr 22 14:23:51 2020 +0100 +++ b/vamp-hostsdk/PluginWrapper.h Thu Apr 23 11:39:34 2020 +0100 @@ -56,6 +56,9 @@ * override only the methods that are meaningful for the particular * adapter. * + * A PluginWrapper takes ownership of the plugin it wraps, and deletes + * it when it is itself deleted. To prevent this, call disownPlugin(). + * * \note This class was introduced in version 1.1 of the Vamp plugin SDK. */ @@ -121,9 +124,25 @@ return 0; } + /** + * Disown the wrapped plugin, so that we no longer delete it on + * our own destruction. The identity of the wrapped plugin is + * unchanged, but this switches the expectation about ownership so + * that the caller is expected to handle the lifecycle of the + * wrapped plugin and to ensure that it outlasts this wrapper. + * + * This is not the normal model, but could be useful in situations + * where a plugin is already managed using a smart pointer model + * before being adapted into this wrapper. Note that this can't be + * reversed - if you call this, you must subsequently take charge + * of the wrapped plugin yourself. + */ + void disownPlugin(); + protected: PluginWrapper(Plugin *plugin); // I take ownership of plugin Plugin *m_plugin; + bool m_pluginIsOwned; }; }