1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-11-23 17:30:17 +01:00

Complementary un-registration of providers; change function name

This commit is contained in:
Paul Licameli
2020-10-02 14:30:53 -04:00
parent 64bbc31c54
commit 861470dd77
3 changed files with 28 additions and 4 deletions

View File

@@ -164,12 +164,15 @@ static ModuleInterface * name(const wxString *path)
// Provides the base for embedded module registration. If used, a Register() // Provides the base for embedded module registration. If used, a Register()
// method must be supplied explicitly. // method must be supplied explicitly.
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#define DECLARE_BUILTIN_MODULE_BASE(name) \ #define DECLARE_BUILTIN_MODULE_BASE(name) \
class name \ class name \
{ \ { \
public: \ public: \
name() {Register();} \ name() {Register();} \
~name() {Unregister();} \
void Register(); \ void Register(); \
void Unregister(); \
}; \ }; \
static name name ## _instance; static name name ## _instance;
@@ -181,7 +184,11 @@ static name name ## _instance;
DECLARE_BUILTIN_MODULE_BASE(name) \ DECLARE_BUILTIN_MODULE_BASE(name) \
void name::Register() \ void name::Register() \
{ \ { \
RegisterBuiltinModule(MODULE_ENTRY); \ RegisterProvider(MODULE_ENTRY); \
} \
void name::Unregister() \
{ \
UnregisterProvider(MODULE_ENTRY); \
} }
#else #else

View File

@@ -182,13 +182,23 @@ namespace {
} }
} }
void RegisterBuiltinModule(ModuleMain moduleMain) void RegisterProvider(ModuleMain moduleMain)
{ {
builtinModuleList().push_back(moduleMain); auto &list = builtinModuleList();
if ( moduleMain )
list.push_back(moduleMain);
return; return;
} }
void UnregisterProvider(ModuleMain moduleMain)
{
auto &list = builtinModuleList();
auto end = list.end(), iter = std::find(list.begin(), end, moduleMain);
if (iter != end)
list.erase(iter);
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Creation/Destruction // Creation/Destruction
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -136,6 +136,13 @@ private:
using ModuleMain = ModuleInterface *(*)(const wxString *path); using ModuleMain = ModuleInterface *(*)(const wxString *path);
AUDACITY_DLL_API AUDACITY_DLL_API
void RegisterBuiltinModule(ModuleMain rtn); void RegisterProvider(ModuleMain rtn);
AUDACITY_DLL_API
void UnregisterProvider(ModuleMain rtn);
// Guarantee the registry exists before any registrations, so it will
// be destroyed only after the un-registrations
static struct Init{
Init() { RegisterProvider(nullptr); } } sInitBuiltinModules;
#endif /* __AUDACITY_MODULEMANAGER_H__ */ #endif /* __AUDACITY_MODULEMANAGER_H__ */