Audacity 3.2.0
PluginProvider.h
Go to the documentation of this file.
1/*!*******************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file PluginProvider.h
6 @brief Generalized interface for discovery of plug-ins for one protocol
7
8 Leland Lucius
9
10 Copyright (c) 2014, Audacity Team
11 All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions
15 are met:
16
17 1. Redistributions of source code must retain the above copyright
18 notice, this list of conditions and the following disclaimer.
19
20 2. Redistributions in binary form must reproduce the above copyright
21 notice, this list of conditions and the following disclaimer in the
22 documentation and/or other materials provided with the distribution.
23
24 3. Neither the name of the copyright holder nor the names of its
25 contributors may be used to endorse or promote products derived from
26 this software without specific prior written permission.
27
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
31 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
32 COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
33 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
34 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
36 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
38 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 POSSIBILITY OF SUCH DAMAGE.
40
41**********************************************************************/
42
43#ifndef __AUDACITY_PLUGINPROVIDER_H__
44#define __AUDACITY_PLUGINPROVIDER_H__
45
46#include <functional>
47#include <memory>
48#include "Identifier.h"
49#include "ComponentInterface.h"
51
52using PluginID = wxString;
53using PluginIDs = wxArrayString;
54// Incomplete type not defined in libraries -- TODO clean that up:
56
57// ============================================================================
58//
59// Don't even think about adding provider types, like effect, importer, etc. in
60// here. The provider interface should not have to change when new types of
61// plug-ins are added to Audacity.
62//
63// In addition a single provider may want to provide multiple plug-in types.
64// ============================================================================
65
66// ============================================================================
73// ============================================================================
74
78class COMPONENTS_API PluginProvider /* not final */
79 : public ComponentInterface
80{
81public:
82
87 //TODO: it may seem reasonable to require providers to perform that check
88 //in DiscoverPluginsAtPath, but some plugin types can safely provide meta
89 //data, which is a good reason to ask to avoid such checks during plugin
90 //discovery...
91 class COMPONENTS_API Validator
92 {
93 public:
95 virtual void Validate(ComponentInterface& pluginInterface) = 0;
96 virtual ~Validator();
97 };
98
99 virtual ~PluginProvider();
100
102
103 virtual bool Initialize() = 0;
104
106 virtual void Terminate() = 0;
107
109
114
116
126 virtual const FileExtensions &GetFileExtensions() = 0;
127
129
133 virtual FilePath InstallPath() = 0;
134
136 virtual void AutoRegisterPlugins(PluginManagerInterface & pluginManager) = 0;
137
138 virtual bool SupportsCustomModulePaths() const;
139
142
149 virtual PluginPaths
151
153
170 using RegistrationCallback = std::function<
172 virtual unsigned DiscoverPluginsAtPath(
173 const PluginPath & path, TranslatableString &errMsg,
174 const RegistrationCallback &callback )
175 = 0;
176
183 virtual bool CheckPluginExist(const PluginPath& path) const = 0;
184
187 virtual std::unique_ptr<Validator> MakeValidator() const;
188
190
193 virtual std::unique_ptr<ComponentInterface>
194 LoadPlugin(const PluginPath & path) = 0;
195};
196
197// ----------------------------------------------------------------------------
198// Since there may be multiple embedded providers, the entry function will
199// be declared static so as not to interfere with other providers during link.
200// ----------------------------------------------------------------------------
201#define DECLARE_PROVIDER_ENTRY(name) \
202static std::unique_ptr<PluginProvider> name()
203
204// ----------------------------------------------------------------------------
205// This will create a class and instance that will register the provider entry
206// point during Audacity startup. At the appropriate time, the entry point
207// will be called to create the provider instance.
208// ----------------------------------------------------------------------------
209
210// ----------------------------------------------------------------------------
211// Provides the base for embedded provider registration. If used, a Register()
212// method must be supplied explicitly.
213// ----------------------------------------------------------------------------
214
215#define DECLARE_BUILTIN_PROVIDER_BASE(name) \
216class name \
217{ \
218public: \
219 name() {Register();} \
220 ~name() {Unregister();} \
221 void Register(); \
222 void Unregister(); \
223}; \
224static name name ## _instance;
225
226// ----------------------------------------------------------------------------
227// Provides the full embedded provider registration process. Nothing further is
228// required (other than supplying the provider entry point function).
229// ----------------------------------------------------------------------------
230#define DECLARE_BUILTIN_PROVIDER(name) \
231DECLARE_BUILTIN_PROVIDER_BASE(name) \
232void name::Register() \
233{ \
234 RegisterProviderFactory(AudacityModule); \
235} \
236void name::Unregister() \
237{ \
238 UnregisterProviderFactory(AudacityModule); \
239}
240
241#endif // __AUDACITY_MODULEINTERFACE_H__
wxString PluginID
std::vector< PluginPath > PluginPaths
Definition: Identifier.h:215
wxString PluginPath
type alias for identifying a Plugin supplied by a module, each module defining its own interpretation...
Definition: Identifier.h:214
wxArrayString PluginIDs
wxString FilePath
Definition: Project.h:21
ComponentInterface provides name / vendor / version functions to identify plugins....
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
virtual void Validate(ComponentInterface &pluginInterface)=0
virtual ~PluginProvider()
virtual EffectFamilySymbol GetOptionalFamilySymbol()=0
A symbol identifying the family of plug-ins provided by this.
virtual unsigned DiscoverPluginsAtPath(const PluginPath &path, TranslatableString &errMsg, const RegistrationCallback &callback)=0
virtual void Terminate()=0
Called just prior to deletion to allow releasing any resources.
virtual PluginPaths FindModulePaths(PluginManagerInterface &pluginManager)=0
virtual std::unique_ptr< ComponentInterface > LoadPlugin(const PluginPath &path)=0
Load the plug-in at a path reported by DiscoverPluginsAtPath.
virtual void AutoRegisterPlugins(PluginManagerInterface &pluginManager)=0
Called so that a provider of a static set of plug-ins can register them.
virtual const FileExtensions & GetFileExtensions()=0
File types associated with this protocol.
std::function< const PluginID &(PluginProvider *, ComponentInterface *) > RegistrationCallback
Further expand a path reported by FindModulePaths.
virtual bool Initialize()=0
Called immediately after creation. Let provider initialize.
virtual bool CheckPluginExist(const PluginPath &path) const =0
Performs plugin/module existence check, still plugin may fail to load. Implementation should avoid lo...
virtual FilePath InstallPath()=0
Where plug-in files should be copied to install them.
Holds a msgid for the translation catalog; may also bind format arguments.
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.