Audacity  2.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 <wx/dynlib.h>
16 
17 #include "MemoryX.h"
18 #include <map>
19 #include <vector>
20 
21 #include "audacity/ModuleInterface.h"
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 
70  ModuleInterface, ModuleInterfaceDeleter
71 >;
72 
73 typedef std::map<wxString, ModuleMain *> ModuleMainMap;
74 typedef std::map<wxString, ModuleInterfaceHandle> ModuleMap;
75 typedef std::map<ModuleInterface *, movable_ptr<wxDynamicLibrary>> LibraryMap;
76 
77 class ModuleManager final : public ModuleManagerInterface
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 RegisterPlugin(const PluginID & provider, const wxString & path);
103 
104  IdentInterface *CreateProviderInstance(const PluginID & provider, const wxString & path);
105  IdentInterface *CreateInstance(const PluginID & provider, const wxString & path);
106  void DeleteInstance(const PluginID & provider, IdentInterface *instance);
107 
108  bool IsProviderValid(const PluginID & provider, const wxString & path);
109  bool IsPluginValid(const PluginID & provider, const wxString & path, bool bFast);
110 
111 private:
112  // I'm a singleton class
113  ModuleManager();
114  ~ModuleManager();
115 
116  void InitializeBuiltins();
117  ModuleInterface *LoadModule(const wxString & path);
118 
119 private:
121  friend std::default_delete<ModuleManager>;
122  static std::unique_ptr<ModuleManager> mInstance;
123 
127 
128  std::vector<movable_ptr<Module>> mModules;
129 };
130 
131 #endif /* __AUDACITY_MODULEMANAGER_H__ */
void * GetSymbol(const wxString &name)
Definition: ModuleManager.cpp:170
Definition: ModuleManager.h:41
wxArrayString FindPluginsForProvider(const PluginID &provider, const wxString &path)
Definition: ModuleManager.cpp:526
Definition: ModuleManager.h:43
int(* fnModuleDispatch)(ModuleDispatchTypes type)
Definition: ModuleManager.h:46
static ModuleManager & Get()
Definition: ModuleManager.cpp:341
wxString PluginID
Definition: CommandFunctors.h:16
bool DiscoverProviders()
Definition: ModuleManager.cpp:351
std::vector< movable_ptr< Module > > mModules
Definition: ModuleManager.h:128
IdentInterface * CreateInstance(const PluginID &provider, const wxString &path)
Definition: ModuleManager.cpp:563
Definition: MemoryX.h:699
static std::unique_ptr< ModuleManager > mInstance
Definition: ModuleManager.h:122
void FindAllPlugins(PluginIDList &providers, wxArrayString &paths)
Definition: ModuleManager.cpp:496
ModuleManager()
Definition: ModuleManager.cpp:205
IdentInterface * CreateProviderInstance(const PluginID &provider, const wxString &path)
Definition: ModuleManager.cpp:552
wxWindow * MakeHijackPanel()
Definition: ModuleManager.cpp:80
Definition: ModuleManager.h:37
int Dispatch(ModuleDispatchTypes type)
Definition: ModuleManager.cpp:161
bool IsProviderValid(const PluginID &provider, const wxString &path)
Definition: ModuleManager.cpp:585
void operator()(ModuleInterface *pInterface) const
Definition: ModuleManager.cpp:459
fnModuleDispatch mDispatch
Definition: ModuleManager.h:62
Definition: ModuleManager.h:39
wxArrayString PluginIDList
Definition: PluginManager.h:168
bool IsPluginValid(const PluginID &provider, const wxString &path, bool bFast)
Definition: ModuleManager.cpp:603
wxString mName
Definition: ModuleManager.h:60
int Dispatch(ModuleDispatchTypes type)
Definition: ModuleManager.cpp:327
void DeleteInstance(const PluginID &provider, IdentInterface *instance)
Definition: ModuleManager.cpp:574
ModuleInterface * LoadModule(const wxString &path)
Definition: ModuleManager.cpp:425
Definition: ModuleManager.h:42
void InitializeBuiltins()
Definition: ModuleManager.cpp:396
Definition: ModuleManager.h:77
virtual ~Module()
Definition: ModuleManager.cpp:98
Module(const wxString &name)
Definition: ModuleManager.cpp:91
Definition: ModuleManager.h:40
Definition: ModuleManager.h:38
Contains methods for applying commands that are passed to it.
Definition: CommandHandler.h:25
Definition: ModuleManager.h:48
Definition: ModuleManager.h:65
ModuleDispatchTypes
Definition: ModuleManager.h:35
ModuleMap mDynModules
Definition: ModuleManager.h:125
bool Load()
Definition: ModuleManager.cpp:102
std::map< wxString, ModuleMain * > ModuleMainMap
Definition: ModuleManager.h:73
std::map< ModuleInterface *, movable_ptr< wxDynamicLibrary > > LibraryMap
Definition: ModuleManager.h:75
const wxChar * name
Definition: Distortion.cpp:94
void RegisterModule(ModuleInterface *module) override
Definition: ModuleManager.cpp:475
void Initialize(CommandHandler &cmdHandler)
Definition: ModuleManager.cpp:216
friend ModuleInterfaceDeleter
Definition: ModuleManager.h:120
bool RegisterPlugin(const PluginID &provider, const wxString &path)
Definition: ModuleManager.cpp:542
void Unload()
Definition: ModuleManager.cpp:152
std::map< wxString, ModuleInterfaceHandle > ModuleMap
Definition: ModuleManager.h:74
LibraryMap mLibs
Definition: ModuleManager.h:126
ModuleMainMap mModuleMains
Definition: ModuleManager.h:124
std::unique_ptr< wxDynamicLibrary > mLib
Definition: ModuleManager.h:61
~ModuleManager()
Definition: ModuleManager.cpp:209