Audacity 3.2.0
ModuleManager.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 ModuleManager.h
6
7 Dominic Mazzoni
8 James Crook
9
10**********************************************************************/
11
12#ifndef __AUDACITY_MODULEMANAGER_H__
13#define __AUDACITY_MODULEMANAGER_H__
14
15#include "MemoryX.h"
16#include <functional>
17#include <map>
18#include <vector>
19#include <wx/string.h>
20
21#include "Identifier.h"
22
23class wxArrayString;
24class wxDynamicLibrary;
26class PluginProvider;
27class wxWindow;
28using PluginID = wxString;
30
31//
32// Module Manager
33//
34// wxPluginManager would be MUCH better, but it's an "undocumented" framework.
35//
36
37#include "ModuleConstants.h"
38
40
41class Module
42{
43public:
44 Module(const FilePath & name);
45 virtual ~Module();
46
47 void ShowLoadFailureError(const wxString &Error);
48 bool Load(wxString &deferredErrorMessage);
49 void Unload();
50 bool HasDispatch() { return mDispatch != NULL; };
52 void * GetSymbol(const wxString &name);
53 const FilePath &GetName() const { return mName; }
54
55private:
57 std::unique_ptr<wxDynamicLibrary> mLib;
59};
60
62 void operator ()(PluginProvider *pInterface) const;
63};
64
65using PluginProviderHandle = std::unique_ptr<
67>;
68
69typedef std::map<wxString, PluginProviderHandle> PluginProviderMap;
70
71class MODULE_MANAGER_API ModuleManager final
72{
73public:
74
75 // -------------------------------------------------------------------------
76 // ModuleManager implementation
77 // -------------------------------------------------------------------------
78
79 static ModuleManager & Get();
80
81 // This string persists in configuration files
82 // So config compatibility will break if it is changed across Audacity versions
83 static wxString GetPluginTypeString();
84
85 static PluginID GetID(PluginProvider *provider);
86
87private:
88 static void FindModules(FilePaths &files);
90 std::vector< std::pair< std::unique_ptr<Module>, wxString > >;
91 static void TryLoadModules(
92 const FilePaths &files, FilePaths &decided, DelayedErrors &errors);
93
94public:
95 void Initialize();
97
98 // PluginManager use
99 // Can be called before Initialize()
100 bool DiscoverProviders();
101
102 // Supports range-for iteration
103 auto Providers() const
104 { return make_iterator_range(mProviders.cbegin(), mProviders.cend()); }
105
106 bool RegisterEffectPlugin(const PluginID & provider, const PluginPath & path,
107 TranslatableString &errMsg);
108
109 PluginProvider *CreateProviderInstance(
110 const PluginID & provider, const PluginPath & path);
111 std::unique_ptr<ComponentInterface>
112 LoadPlugin(const PluginID & provider, const PluginPath & path);
113
114 bool IsProviderValid(const PluginID & provider, const PluginPath & path);
115 bool IsPluginValid(const PluginID & provider, const PluginPath & path, bool bFast);
116
117private:
118 // I'm a singleton class
121 ModuleManager(const ModuleManager&) PROHIBITED;
123
124 void InitializeBuiltins();
125
126private:
128 friend std::default_delete<ModuleManager>;
129 static std::unique_ptr<ModuleManager> mInstance;
130
131 // Providers can each report availability of any number of Plug-Ins
132 // identified by "paths", and are also factories of ComponentInterface
133 // objects for each path
135
136 // Other libraries that receive notifications of events described by
137 // ModuleDispatchTypes:
138 std::vector<std::unique_ptr<Module>> mModules;
139};
140
141// ----------------------------------------------------------------------------
142// The module entry point prototype (a factory of PluginProvider objects)
143// ----------------------------------------------------------------------------
145
146MODULE_MANAGER_API
148MODULE_MANAGER_API
150
151// Guarantee the registry exists before any registrations, so it will
152// be destroyed only after the un-registrations
153static struct Init{
155
156#endif /* __AUDACITY_MODULEMANAGER_H__ */
const TranslatableString name
Definition: Distortion.cpp:82
wxString PluginID
Definition: EffectManager.h:30
static PluginID GetID(EffectPlugin &effect)
Definition: EffectUI.cpp:28
wxString PluginPath
type alias for identifying a Plugin supplied by a module, each module defining its own interpretation...
Definition: Identifier.h:214
IteratorRange< Iterator > make_iterator_range(const Iterator &i1, const Iterator &i2)
Definition: MemoryX.h:423
ModuleDispatchTypes
MODULE_MANAGER_API void RegisterProvider(PluginProviderMain rtn)
static struct Init sInitBuiltinModules
int(* fnModuleDispatch)(ModuleDispatchTypes type)
Definition: ModuleManager.h:39
std::unique_ptr< PluginProvider, PluginProviderDeleter > PluginProviderHandle
Definition: ModuleManager.h:67
std::map< wxString, PluginProviderHandle > PluginProviderMap
Definition: ModuleManager.h:69
PluginProvider *(*)() PluginProviderMain
MODULE_MANAGER_API void UnregisterProvider(PluginProviderMain rtn)
wxString FilePath
Definition: Project.h:20
ComponentInterface provides name / vendor / version functions to identify plugins....
void ShowLoadFailureError(const wxString &Error)
fnModuleDispatch mDispatch
Definition: ModuleManager.h:58
bool HasDispatch()
Definition: ModuleManager.h:50
std::unique_ptr< wxDynamicLibrary > mLib
Definition: ModuleManager.h:57
Module(const FilePath &name)
void * GetSymbol(const wxString &name)
virtual ~Module()
bool Load(wxString &deferredErrorMessage)
int Dispatch(ModuleDispatchTypes type)
const FilePath mName
Definition: ModuleManager.h:56
void Unload()
const FilePath & GetName() const
Definition: ModuleManager.h:53
std::vector< std::pair< std::unique_ptr< Module >, wxString > > DelayedErrors
Definition: ModuleManager.h:90
static std::unique_ptr< ModuleManager > mInstance
ModuleManager & operator=(const ModuleManager &) PROHIBITED
friend PluginProviderDeleter
auto Providers() const
PluginProviderMap mProviders
ModuleManager(const ModuleManager &) PROHIBITED
std::vector< std::unique_ptr< Module > > mModules
Holds a msgid for the translation catalog; may also bind format arguments.
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:26
bool Dispatch()
Definition: Journal.cpp:202
void operator()(PluginProvider *pInterface) const