Audacity  2.2.2
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 <wx/dynlib.h>
16 
17 #include "MemoryX.h"
18 #include <map>
19 #include <vector>
20 
22 #include "PluginManager.h"
23 
24 class CommandHandler;
25 
26 wxWindow * MakeHijackPanel();
27 
28 //
29 // Module Manager
30 //
31 // wxPluginManager would be MUCH better, but it's an "undocumented" framework.
32 //
33 #define ModuleDispatchName "ModuleDispatch"
34 
35 typedef enum
36 {
45 
47 
48 class Module
49 {
50 public:
51  Module(const wxString & name);
52  virtual ~Module();
53 
54  bool Load();
55  void Unload();
56  int Dispatch(ModuleDispatchTypes type);
57  void * GetSymbol(const wxString &name);
58 
59 private:
60  wxString mName;
61  std::unique_ptr<wxDynamicLibrary> mLib;
63 };
64 
66  void operator ()(ModuleInterface *pInterface) const;
67 };
68 
69 using ModuleInterfaceHandle = std::unique_ptr<
71 >;
72 
73 typedef std::map<wxString, ModuleMain *> ModuleMainMap;
74 typedef std::map<wxString, ModuleInterfaceHandle> ModuleMap;
75 typedef std::map<ModuleInterface *, std::unique_ptr<wxDynamicLibrary>> LibraryMap;
76 
78 {
79 public:
80  // -------------------------------------------------------------------------
81  // ModuleManagerInterface implementation
82  // -------------------------------------------------------------------------
83 
84  void RegisterModule(ModuleInterface *module) override;
85 
86  // -------------------------------------------------------------------------
87  // ModuleManager implementation
88  // -------------------------------------------------------------------------
89 
90  static ModuleManager & Get();
91 
92  void Initialize(CommandHandler & cmdHandler);
93  int Dispatch(ModuleDispatchTypes type);
94 
95  // PluginManager use
96  bool DiscoverProviders();
97 
98  // Seems we don't currently use FindAllPlugins
99  void FindAllPlugins(PluginIDList & providers, wxArrayString & paths);
100 
101  wxArrayString FindPluginsForProvider(const PluginID & provider, const wxString & path);
102  bool RegisterEffectPlugin(const PluginID & provider, const wxString & path,
103  wxString &errMsg);
104 
105  IdentInterface *CreateProviderInstance(const PluginID & provider, const wxString & path);
106  IdentInterface *CreateInstance(const PluginID & provider, const wxString & path);
107  void DeleteInstance(const PluginID & provider, IdentInterface *instance);
108 
109  bool IsProviderValid(const PluginID & provider, const wxString & path);
110  bool IsPluginValid(const PluginID & provider, const wxString & path, bool bFast);
111 
112 private:
113  // I'm a singleton class
114  ModuleManager();
115  ~ModuleManager();
116 
117  void InitializeBuiltins();
118  ModuleInterface *LoadModule(const wxString & path);
119 
120 private:
122  friend std::default_delete<ModuleManager>;
123  static std::unique_ptr<ModuleManager> mInstance;
124 
128 
129  std::vector<std::unique_ptr<Module>> mModules;
130 };
131 
132 #endif /* __AUDACITY_MODULEMANAGER_H__ */
void * GetSymbol(const wxString &name)
std::map< ModuleInterface *, std::unique_ptr< wxDynamicLibrary > > LibraryMap
Definition: ModuleManager.h:75
wxArrayString FindPluginsForProvider(const PluginID &provider, const wxString &path)
int(* fnModuleDispatch)(ModuleDispatchTypes type)
Definition: ModuleManager.h:46
static ModuleManager & Get()
bool DiscoverProviders()
IdentInterface * CreateInstance(const PluginID &provider, const wxString &path)
static std::unique_ptr< ModuleManager > mInstance
wxString PluginID
Definition: Types.h:209
void FindAllPlugins(PluginIDList &providers, wxArrayString &paths)
IdentInterface * CreateProviderInstance(const PluginID &provider, const wxString &path)
wxWindow * MakeHijackPanel()
int Dispatch(ModuleDispatchTypes type)
bool IsProviderValid(const PluginID &provider, const wxString &path)
void operator()(ModuleInterface *pInterface) const
fnModuleDispatch mDispatch
Definition: ModuleManager.h:62
wxArrayString PluginIDList
bool IsPluginValid(const PluginID &provider, const wxString &path, bool bFast)
wxString mName
Definition: ModuleManager.h:60
int Dispatch(ModuleDispatchTypes type)
std::vector< std::unique_ptr< Module > > mModules
void DeleteInstance(const PluginID &provider, IdentInterface *instance)
ModuleInterface * LoadModule(const wxString &path)
void InitializeBuiltins()
virtual ~Module()
Module(const wxString &name)
Contains methods for applying commands that are passed to it.
ModuleDispatchTypes
Definition: ModuleManager.h:35
ModuleMap mDynModules
bool Load()
std::map< wxString, ModuleMain * > ModuleMainMap
Definition: ModuleManager.h:73
const wxChar * name
Definition: Distortion.cpp:94
void RegisterModule(ModuleInterface *module) override
void Initialize(CommandHandler &cmdHandler)
friend ModuleInterfaceDeleter
void Unload()
std::map< wxString, ModuleInterfaceHandle > ModuleMap
Definition: ModuleManager.h:74
bool RegisterEffectPlugin(const PluginID &provider, const wxString &path, wxString &errMsg)
std::unique_ptr< ModuleInterface, ModuleInterfaceDeleter > ModuleInterfaceHandle
Definition: ModuleManager.h:71
LibraryMap mLibs
IdentInterface provides name / vendor / version functions to identify plugins. It is what makes a cla...
ModuleMainMap mModuleMains
std::unique_ptr< wxDynamicLibrary > mLib
Definition: ModuleManager.h:61