mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-16 08:09:32 +02:00
ModuleInterface.h needn't distinguish built-in from external usage...
... All is set up so that plug-in providers can be modules that register their instance-creating function pointers directly with RegisterProvider; no special symbol name needs to be exported. That is, they now just need to export ModuleDispatch and GetVersionString, just like other modules for other purposes. Duplication of logic from ModuleManager::InitializeBuiltins() is removed. No examples yet in the previous commits, but it does work in my misc-modules branch.
This commit is contained in:
parent
a4c3840861
commit
6242be0a8e
@ -135,18 +135,6 @@ public:
|
||||
virtual void DeleteInstance(ComponentInterface *instance) = 0;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// 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.
|
||||
// ----------------------------------------------------------------------------
|
||||
#define MODULE_ENTRY AudacityModule
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// If BUILDING_AUDACITY is defined during the current build, it is assumed
|
||||
// that the module wishes to be embedded in the Audacity executable.
|
||||
// ----------------------------------------------------------------------------
|
||||
#if defined(BUILDING_AUDACITY)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Since there may be multiple embedded modules, the module entry function will
|
||||
// be declared static so as not to interfere with other modules during link.
|
||||
@ -184,31 +172,11 @@ static name name ## _instance;
|
||||
DECLARE_BUILTIN_MODULE_BASE(name) \
|
||||
void name::Register() \
|
||||
{ \
|
||||
RegisterProvider(MODULE_ENTRY); \
|
||||
RegisterProvider(AudacityModule); \
|
||||
} \
|
||||
void name::Unregister() \
|
||||
{ \
|
||||
UnregisterProvider(MODULE_ENTRY); \
|
||||
UnregisterProvider(AudacityModule); \
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// When building as an external module, the entry point must be declared with
|
||||
// "C" linkage and whatever method is used to make the function externally
|
||||
// visible.
|
||||
// ----------------------------------------------------------------------------
|
||||
#define DECLARE_MODULE_ENTRY(name) \
|
||||
extern "C" __declspec(dllexport) \
|
||||
ModuleInterface * name(const wxString *path)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Define these as empty will effectively remove the embedded registration
|
||||
// functionality.
|
||||
// ----------------------------------------------------------------------------
|
||||
#define DECLARE_BUILTIN_MODULE_BASE(name)
|
||||
#define DECLARE_BUILTIN_MODULE(name)
|
||||
|
||||
#endif
|
||||
|
||||
#endif // __AUDACITY_MODULEINTERFACE_H__
|
||||
|
@ -461,7 +461,7 @@ void ModuleManager::InitializeBuiltins()
|
||||
moduleMain(nullptr), ModuleInterfaceDeleter{}
|
||||
};
|
||||
|
||||
if (module->Initialize())
|
||||
if (module && module->Initialize())
|
||||
{
|
||||
// Register the provider
|
||||
ModuleInterface *pInterface = module.get();
|
||||
@ -480,40 +480,6 @@ void ModuleManager::InitializeBuiltins()
|
||||
}
|
||||
}
|
||||
|
||||
ModuleInterface *ModuleManager::LoadModule(const PluginPath & path)
|
||||
{
|
||||
auto lib = std::make_unique<wxDynamicLibrary>();
|
||||
|
||||
if (lib->Load(path, wxDL_NOW))
|
||||
{
|
||||
bool success = false;
|
||||
ModuleMain audacityMain = (ModuleMain) lib->GetSymbol(wxSTRINGIZE_T(MODULE_ENTRY),
|
||||
&success);
|
||||
if (success && audacityMain)
|
||||
{
|
||||
ModuleInterfaceHandle handle {
|
||||
audacityMain(&path), ModuleInterfaceDeleter{}
|
||||
};
|
||||
if (handle)
|
||||
{
|
||||
if (handle->Initialize())
|
||||
{
|
||||
|
||||
auto module = handle.get();
|
||||
mDynModules[PluginManager::GetID(module)] = std::move(handle);
|
||||
mLibs[module] = std::move(lib);
|
||||
|
||||
return module;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lib->Unload();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ModuleInterfaceDeleter::operator() (ModuleInterface *pInterface) const
|
||||
{
|
||||
if (pInterface)
|
||||
@ -567,7 +533,7 @@ ModuleInterface *ModuleManager::CreateProviderInstance(const PluginID & provider
|
||||
return mDynModules[providerID].get();
|
||||
}
|
||||
|
||||
return LoadModule(path);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ComponentInterface *ModuleManager::CreateInstance(const PluginID & providerID,
|
||||
|
@ -109,7 +109,6 @@ private:
|
||||
ModuleManager &operator=(const ModuleManager&) PROHIBITED;
|
||||
|
||||
void InitializeBuiltins();
|
||||
ModuleInterface *LoadModule(const PluginPath & path);
|
||||
|
||||
private:
|
||||
friend ModuleInterfaceDeleter;
|
||||
|
Loading…
x
Reference in New Issue
Block a user