1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-11 09:31:13 +02:00

Module manager (#549)

* Eliminate ModuleManagerInterface...

... It was there only to provide RegisterModule(), but that was not used
anywhere.  So simplify.

* Remove nested #include of ModuleInterface.h
This commit is contained in:
Paul Licameli 2020-05-29 11:48:52 -04:00 committed by GitHub
parent 5bede69d11
commit 9360359e9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 35 additions and 99 deletions

View File

@ -135,20 +135,6 @@ public:
virtual void DeleteInstance(ComponentInterface *instance) = 0; virtual void DeleteInstance(ComponentInterface *instance) = 0;
}; };
// ============================================================================
//
// ModuleManagerInterface class
//
// ============================================================================
class ModuleManagerInterface /* not final */
{
public:
// Modules call this to register their interface
virtual void RegisterModule(ModuleInterface *module) = 0;
};
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// The default entry point name and the name that will be searched for during // The default entry point name and the name that will be searched for during
// load if the module has been built as a external library. // load if the module has been built as a external library.
@ -158,8 +144,7 @@ public:
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// The module entry point prototype // The module entry point prototype
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
typedef ModuleInterface *(*ModuleMain)(ModuleManagerInterface *moduleManager, typedef ModuleInterface *(*ModuleMain)(const wxString *path);
const wxString *path);
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// If BUILDING_AUDACITY is defined during the current build, it is assumed // If BUILDING_AUDACITY is defined during the current build, it is assumed
@ -172,7 +157,7 @@ typedef ModuleInterface *(*ModuleMain)(ModuleManagerInterface *moduleManager,
// be declared static so as not to interfere with other modules during link. // be declared static so as not to interfere with other modules during link.
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#define DECLARE_MODULE_ENTRY(name) \ #define DECLARE_MODULE_ENTRY(name) \
static ModuleInterface * name(ModuleManagerInterface *moduleManager, const wxString *path) static ModuleInterface * name(const wxString *path)
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// This will create a class and instnace that will register the module entry // This will create a class and instnace that will register the module entry
@ -214,8 +199,7 @@ void name::Register() \
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#define DECLARE_MODULE_ENTRY(name) \ #define DECLARE_MODULE_ENTRY(name) \
extern "C" __declspec(dllexport) \ extern "C" __declspec(dllexport) \
ModuleInterface * name(ModuleManagerInterface *moduleManager, \ ModuleInterface * name(const wxString *path)
const wxString *path)
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Define these as empty will effectively remove the embedded registration // Define these as empty will effectively remove the embedded registration

View File

@ -46,7 +46,6 @@
#include "audacity/EffectInterface.h" #include "audacity/EffectInterface.h"
#include "audacity/ComponentInterface.h" #include "audacity/ComponentInterface.h"
#include "audacity/ImporterInterface.h" #include "audacity/ImporterInterface.h"
#include "audacity/ModuleInterface.h"
class ModuleInterface; class ModuleInterface;

View File

@ -20,6 +20,7 @@ i.e. an alternative to the usual interface, for Audacity.
#include "Audacity.h" #include "Audacity.h"
#include "ModuleManager.h" #include "ModuleManager.h"
#include "audacity/ModuleInterface.h"
#include "Experimental.h" #include "Experimental.h"
@ -446,7 +447,7 @@ void ModuleManager::InitializeBuiltins()
for (auto moduleMain : builtinModuleList()) for (auto moduleMain : builtinModuleList())
{ {
ModuleInterfaceHandle module { ModuleInterfaceHandle module {
moduleMain(this, NULL), ModuleInterfaceDeleter{} moduleMain(nullptr), ModuleInterfaceDeleter{}
}; };
if (module->Initialize()) if (module->Initialize())
@ -480,7 +481,7 @@ ModuleInterface *ModuleManager::LoadModule(const PluginPath & path)
if (success && audacityMain) if (success && audacityMain)
{ {
ModuleInterfaceHandle handle { ModuleInterfaceHandle handle {
audacityMain(this, &path), ModuleInterfaceDeleter{} audacityMain(&path), ModuleInterfaceDeleter{}
}; };
if (handle) if (handle)
{ {
@ -518,27 +519,6 @@ void ModuleInterfaceDeleter::operator() (ModuleInterface *pInterface) const
} }
} }
void ModuleManager::RegisterModule(ModuleInterface *inModule)
{
std::unique_ptr<ModuleInterface> module{ inModule };
PluginID id = PluginManager::GetID(module.get());
if (mDynModules.find(id) != mDynModules.end())
{
// TODO: Should we complain about a duplicate registration????
// PRL: Don't leak resources!
module->Terminate();
return;
}
mDynModules[id] = ModuleInterfaceHandle {
module.release(), ModuleInterfaceDeleter{}
};
PluginManager::Get().RegisterPlugin(inModule);
}
PluginPaths ModuleManager::FindPluginsForProvider(const PluginID & providerID, PluginPaths ModuleManager::FindPluginsForProvider(const PluginID & providerID,
const PluginPath & path) const PluginPath & path)
{ {

View File

@ -16,11 +16,13 @@
#include <map> #include <map>
#include <vector> #include <vector>
#include "audacity/ModuleInterface.h" #include "audacity/Types.h"
class wxArrayString; class wxArrayString;
class wxDynamicLibrary; class wxDynamicLibrary;
class CommandHandler; class CommandHandler;
class ComponentInterface;
class ModuleInterface;
wxWindow * MakeHijackPanel(); wxWindow * MakeHijackPanel();
@ -73,14 +75,9 @@ typedef std::map<wxString, ModuleInterfaceHandle> ModuleMap;
typedef std::map<ModuleInterface *, std::unique_ptr<wxDynamicLibrary>> LibraryMap; typedef std::map<ModuleInterface *, std::unique_ptr<wxDynamicLibrary>> LibraryMap;
using PluginIDs = wxArrayString; using PluginIDs = wxArrayString;
class ModuleManager final : public ModuleManagerInterface class ModuleManager final
{ {
public: public:
// -------------------------------------------------------------------------
// ModuleManagerInterface implementation
// -------------------------------------------------------------------------
void RegisterModule(ModuleInterface *module) override;
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// ModuleManager implementation // ModuleManager implementation

View File

@ -40,6 +40,7 @@ for shared and private configs - which need to move out.
#include <wx/utils.h> #include <wx/utils.h>
#include "audacity/EffectInterface.h" #include "audacity/EffectInterface.h"
#include "audacity/ModuleInterface.h"
#include "FileNames.h" #include "FileNames.h"
#include "ModuleManager.h" #include "ModuleManager.h"

View File

@ -18,7 +18,6 @@
#include "audacity/EffectInterface.h" #include "audacity/EffectInterface.h"
#include "audacity/ImporterInterface.h" #include "audacity/ImporterInterface.h"
#include "audacity/ModuleInterface.h"
#include "audacity/PluginInterface.h" #include "audacity/PluginInterface.h"
class wxArrayString; class wxArrayString;

View File

@ -55,7 +55,7 @@ DECLARE_MODULE_ENTRY(AudacityModule)
{ {
// Create and register the importer // Create and register the importer
// Trust the module manager not to leak this // Trust the module manager not to leak this
return safenew BuiltinCommandsModule(moduleManager, path); return safenew BuiltinCommandsModule(path);
} }
// ============================================================================ // ============================================================================
@ -69,10 +69,8 @@ DECLARE_BUILTIN_MODULE(BuiltinsCommandBuiltin);
// //
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
BuiltinCommandsModule::BuiltinCommandsModule(ModuleManagerInterface *moduleManager, BuiltinCommandsModule::BuiltinCommandsModule(const wxString *path)
const wxString *path)
{ {
mModMan = moduleManager;
if (path) if (path)
{ {
mPath = *path; mPath = *path;

View File

@ -27,7 +27,7 @@ class AudacityCommand;
class BuiltinCommandsModule final : public ModuleInterface class BuiltinCommandsModule final : public ModuleInterface
{ {
public: public:
BuiltinCommandsModule(ModuleManagerInterface *moduleManager, const wxString *path); BuiltinCommandsModule(const wxString *path);
virtual ~BuiltinCommandsModule(); virtual ~BuiltinCommandsModule();
using Factory = std::function< std::unique_ptr<AudacityCommand> () >; using Factory = std::function< std::unique_ptr<AudacityCommand> () >;
@ -80,7 +80,6 @@ private:
static void DoRegistration( static void DoRegistration(
const ComponentInterfaceSymbol &name, const Factory &factory ); const ComponentInterfaceSymbol &name, const Factory &factory );
ModuleManagerInterface *mModMan;
wxString mPath; wxString mPath;
using CommandHash = std::unordered_map< wxString, const Entry* > ; using CommandHash = std::unordered_map< wxString, const Entry* > ;

View File

@ -53,7 +53,7 @@ DECLARE_MODULE_ENTRY(AudacityModule)
{ {
// Create and register the importer // Create and register the importer
// Trust the module manager not to leak this // Trust the module manager not to leak this
return safenew BuiltinEffectsModule(moduleManager, path); return safenew BuiltinEffectsModule(path);
} }
// ============================================================================ // ============================================================================
@ -67,10 +67,8 @@ DECLARE_BUILTIN_MODULE(BuiltinsEffectBuiltin);
// //
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
BuiltinEffectsModule::BuiltinEffectsModule(ModuleManagerInterface *moduleManager, BuiltinEffectsModule::BuiltinEffectsModule(const wxString *path)
const wxString *path)
{ {
mModMan = moduleManager;
if (path) if (path)
{ {
mPath = *path; mPath = *path;

View File

@ -26,7 +26,7 @@ class Effect;
class BuiltinEffectsModule final : public ModuleInterface class BuiltinEffectsModule final : public ModuleInterface
{ {
public: public:
BuiltinEffectsModule(ModuleManagerInterface *moduleManager, const wxString *path); BuiltinEffectsModule(const wxString *path);
virtual ~BuiltinEffectsModule(); virtual ~BuiltinEffectsModule();
using Factory = std::function< std::unique_ptr<Effect> () >; using Factory = std::function< std::unique_ptr<Effect> () >;
@ -79,7 +79,6 @@ private:
const ComponentInterfaceSymbol &name, const Factory &factory, const ComponentInterfaceSymbol &name, const Factory &factory,
bool excluded ); bool excluded );
ModuleManagerInterface *mModMan;
PluginPath mPath; PluginPath mPath;
struct Entry; struct Entry;

View File

@ -143,7 +143,7 @@ DECLARE_MODULE_ENTRY(AudacityModule)
{ {
// Create our effects module and register // Create our effects module and register
// Trust the module manager not to leak this // Trust the module manager not to leak this
return safenew VSTEffectsModule(moduleManager, path); return safenew VSTEffectsModule(path);
} }
// ============================================================================ // ============================================================================
@ -306,10 +306,8 @@ public:
// VSTEffectsModule // VSTEffectsModule
// //
// ============================================================================ // ============================================================================
VSTEffectsModule::VSTEffectsModule(ModuleManagerInterface *moduleManager, VSTEffectsModule::VSTEffectsModule(const wxString *path)
const wxString *path)
{ {
mModMan = moduleManager;
if (path) if (path)
{ {
mPath = *path; mPath = *path;

View File

@ -403,7 +403,7 @@ private:
class VSTEffectsModule final : public ModuleInterface class VSTEffectsModule final : public ModuleInterface
{ {
public: public:
VSTEffectsModule(ModuleManagerInterface *moduleManager, const wxString *path); VSTEffectsModule(const wxString *path);
virtual ~VSTEffectsModule(); virtual ~VSTEffectsModule();
// ComponentInterface implementation // ComponentInterface implementation
@ -440,7 +440,6 @@ public:
static void Check(const wxChar *path); static void Check(const wxChar *path);
private: private:
ModuleManagerInterface *mModMan;
PluginPath mPath; PluginPath mPath;
}; };

View File

@ -232,7 +232,7 @@ DECLARE_MODULE_ENTRY(AudacityModule)
{ {
// Create and register the importer // Create and register the importer
// Trust the module manager not to leak this // Trust the module manager not to leak this
return safenew AudioUnitEffectsModule(moduleManager, path); return safenew AudioUnitEffectsModule(path);
} }
// ============================================================================ // ============================================================================
@ -246,10 +246,8 @@ DECLARE_BUILTIN_MODULE(AudioUnitEffectsBuiltin);
// //
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
AudioUnitEffectsModule::AudioUnitEffectsModule(ModuleManagerInterface *moduleManager, AudioUnitEffectsModule::AudioUnitEffectsModule(const wxString *path)
const wxString *path)
{ {
mModMan = moduleManager;
if (path) if (path)
{ {
mPath = *path; mPath = *path;

View File

@ -232,7 +232,7 @@ private:
class AudioUnitEffectsModule final : public ModuleInterface class AudioUnitEffectsModule final : public ModuleInterface
{ {
public: public:
AudioUnitEffectsModule(ModuleManagerInterface *moduleManager, const wxString *path); AudioUnitEffectsModule(const wxString *path);
virtual ~AudioUnitEffectsModule(); virtual ~AudioUnitEffectsModule();
// ComponentInterface implementation // ComponentInterface implementation
@ -273,7 +273,6 @@ public:
OSType ToOSType(const wxString & type); OSType ToOSType(const wxString & type);
private: private:
ModuleManagerInterface *mModMan;
wxString mPath; wxString mPath;
}; };

View File

@ -85,7 +85,7 @@ DECLARE_MODULE_ENTRY(AudacityModule)
{ {
// Create and register the importer // Create and register the importer
// Trust the module manager not to leak this // Trust the module manager not to leak this
return safenew LadspaEffectsModule(moduleManager, path); return safenew LadspaEffectsModule(path);
} }
// ============================================================================ // ============================================================================
@ -99,10 +99,8 @@ DECLARE_BUILTIN_MODULE(LadspaBuiltin);
// //
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
LadspaEffectsModule::LadspaEffectsModule(ModuleManagerInterface *moduleManager, LadspaEffectsModule::LadspaEffectsModule(const wxString *path)
const wxString *path)
{ {
mModMan = moduleManager;
if (path) if (path)
{ {
mPath = *path; mPath = *path;

View File

@ -208,7 +208,7 @@ private:
class LadspaEffectsModule final : public ModuleInterface class LadspaEffectsModule final : public ModuleInterface
{ {
public: public:
LadspaEffectsModule(ModuleManagerInterface *moduleManager, const wxString *path); LadspaEffectsModule(const wxString *path);
virtual ~LadspaEffectsModule(); virtual ~LadspaEffectsModule();
// ComponentInterface implementation // ComponentInterface implementation
@ -245,7 +245,6 @@ public:
FilePaths GetSearchPaths(); FilePaths GetSearchPaths();
private: private:
ModuleManagerInterface *mModMan;
wxString mPath; wxString mPath;
}; };

View File

@ -59,7 +59,7 @@ DECLARE_MODULE_ENTRY(AudacityModule)
{ {
// Create and register the importer // Create and register the importer
// Trust the module manager not to leak this // Trust the module manager not to leak this
return safenew LV2EffectsModule(moduleManager, path); return safenew LV2EffectsModule(path);
} }
// ============================================================================ // ============================================================================
@ -76,10 +76,8 @@ using UriHash = std::unordered_map<wxString, LilvNode*>;
LilvWorld *gWorld = NULL; LilvWorld *gWorld = NULL;
LV2EffectsModule::LV2EffectsModule(ModuleManagerInterface *moduleManager, LV2EffectsModule::LV2EffectsModule(const wxString *path)
const wxString *path)
{ {
mModMan = moduleManager;
if (path) if (path)
{ {
mPath = *path; mPath = *path;

View File

@ -163,7 +163,7 @@
class LV2EffectsModule final : public ModuleInterface class LV2EffectsModule final : public ModuleInterface
{ {
public: public:
LV2EffectsModule(ModuleManagerInterface *moduleManager, const wxString *path); LV2EffectsModule(const wxString *path);
virtual ~LV2EffectsModule(); virtual ~LV2EffectsModule();
// ComponentInterface implementation // ComponentInterface implementation
@ -201,7 +201,6 @@ private:
const LilvPlugin *GetPlugin(const PluginPath & path); const LilvPlugin *GetPlugin(const PluginPath & path);
private: private:
ModuleManagerInterface *mModMan;
PluginPath mPath; PluginPath mPath;
}; };

View File

@ -66,7 +66,7 @@ DECLARE_MODULE_ENTRY(AudacityModule)
{ {
// Create and register the importer // Create and register the importer
// Trust the module manager not to leak this // Trust the module manager not to leak this
return safenew NyquistEffectsModule(moduleManager, path); return safenew NyquistEffectsModule(path);
} }
// ============================================================================ // ============================================================================
@ -80,10 +80,8 @@ DECLARE_BUILTIN_MODULE(NyquistsEffectBuiltin);
// //
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
NyquistEffectsModule::NyquistEffectsModule(ModuleManagerInterface *moduleManager, NyquistEffectsModule::NyquistEffectsModule(const wxString *path)
const wxString *path)
{ {
mModMan = moduleManager;
if (path) if (path)
{ {
mPath = *path; mPath = *path;

View File

@ -21,7 +21,7 @@
class NyquistEffectsModule final : public ModuleInterface class NyquistEffectsModule final : public ModuleInterface
{ {
public: public:
NyquistEffectsModule(ModuleManagerInterface *moduleManager, const wxString *path); NyquistEffectsModule(const wxString *path);
virtual ~NyquistEffectsModule(); virtual ~NyquistEffectsModule();
// ComponentInterface implementation // ComponentInterface implementation
@ -57,6 +57,5 @@ public:
// NyquistEffectModule implementation // NyquistEffectModule implementation
private: private:
ModuleManagerInterface *mModMan;
PluginPath mPath; PluginPath mPath;
}; };

View File

@ -37,7 +37,7 @@ DECLARE_MODULE_ENTRY(AudacityModule)
{ {
// Create and register the importer // Create and register the importer
// Trust the module manager not to leak this // Trust the module manager not to leak this
return safenew VampEffectsModule(moduleManager, path); return safenew VampEffectsModule(path);
} }
// ============================================================================ // ============================================================================
@ -51,10 +51,8 @@ DECLARE_BUILTIN_MODULE(VampsEffectBuiltin);
// //
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
VampEffectsModule::VampEffectsModule(ModuleManagerInterface *moduleManager, VampEffectsModule::VampEffectsModule(const wxString *path)
const wxString *path)
{ {
mModMan = moduleManager;
if (path) if (path)
{ {
mPath = *path; mPath = *path;

View File

@ -29,7 +29,7 @@
class VampEffectsModule final : public ModuleInterface class VampEffectsModule final : public ModuleInterface
{ {
public: public:
VampEffectsModule(ModuleManagerInterface *moduleManager, const wxString *path); VampEffectsModule(const wxString *path);
virtual ~VampEffectsModule(); virtual ~VampEffectsModule();
// ComponentInterface implementation // ComponentInterface implementation
@ -69,7 +69,6 @@ private:
bool & hasParameters); bool & hasParameters);
private: private:
ModuleManagerInterface *mModMan;
PluginPath mPath; PluginPath mPath;
}; };