comparison vamp-hostsdk/PluginWrapper.h @ 538:8ffb8985ae8f

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
author Chris Cannam
date Thu, 23 Apr 2020 11:39:34 +0100
parents c97e70ed5abc
children
comparison
equal deleted inserted replaced
537:b9422f3e63a4 538:8ffb8985ae8f
53 * a pointer to a "to be wrapped" Vamp plugin on construction, and 53 * a pointer to a "to be wrapped" Vamp plugin on construction, and
54 * provides implementations of all the Vamp plugin methods that simply 54 * provides implementations of all the Vamp plugin methods that simply
55 * delegate through to the wrapped plugin. A subclass can therefore 55 * delegate through to the wrapped plugin. A subclass can therefore
56 * override only the methods that are meaningful for the particular 56 * override only the methods that are meaningful for the particular
57 * adapter. 57 * adapter.
58 *
59 * A PluginWrapper takes ownership of the plugin it wraps, and deletes
60 * it when it is itself deleted. To prevent this, call disownPlugin().
58 * 61 *
59 * \note This class was introduced in version 1.1 of the Vamp plugin SDK. 62 * \note This class was introduced in version 1.1 of the Vamp plugin SDK.
60 */ 63 */
61 64
62 class PluginWrapper : public Plugin 65 class PluginWrapper : public Plugin
119 PluginWrapper *pw = dynamic_cast<PluginWrapper *>(m_plugin); 122 PluginWrapper *pw = dynamic_cast<PluginWrapper *>(m_plugin);
120 if (pw) return pw->getWrapper<WrapperType>(); 123 if (pw) return pw->getWrapper<WrapperType>();
121 return 0; 124 return 0;
122 } 125 }
123 126
127 /**
128 * Disown the wrapped plugin, so that we no longer delete it on
129 * our own destruction. The identity of the wrapped plugin is
130 * unchanged, but this switches the expectation about ownership so
131 * that the caller is expected to handle the lifecycle of the
132 * wrapped plugin and to ensure that it outlasts this wrapper.
133 *
134 * This is not the normal model, but could be useful in situations
135 * where a plugin is already managed using a smart pointer model
136 * before being adapted into this wrapper. Note that this can't be
137 * reversed - if you call this, you must subsequently take charge
138 * of the wrapped plugin yourself.
139 */
140 void disownPlugin();
141
124 protected: 142 protected:
125 PluginWrapper(Plugin *plugin); // I take ownership of plugin 143 PluginWrapper(Plugin *plugin); // I take ownership of plugin
126 Plugin *m_plugin; 144 Plugin *m_plugin;
145 bool m_pluginIsOwned;
127 }; 146 };
128 147
129 } 148 }
130 149
131 } 150 }