Audacity 3.2.0
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
BuiltinCommandsModule Class Referencefinal

Internal module to auto register all built in commands. It is closely modelled on BuiltinEffectsModule. More...

#include <LoadCommands.h>

Inheritance diagram for BuiltinCommandsModule:
[legend]
Collaboration diagram for BuiltinCommandsModule:
[legend]

Classes

struct  Entry
 
struct  Registration
 

Public Types

using Factory = std::function< std::unique_ptr< AudacityCommand >() >
 
- Public Types inherited from PluginProvider
using RegistrationCallback = std::function< const PluginID &(PluginProvider *, ComponentInterface *) >
 Further expand a path reported by FindModulePaths. More...
 

Public Member Functions

 BuiltinCommandsModule ()
 
virtual ~BuiltinCommandsModule ()
 
PluginPath GetPath () const override
 
ComponentInterfaceSymbol GetSymbol () const override
 
VendorSymbol GetVendor () const override
 
wxString GetVersion () const override
 
TranslatableString GetDescription () const override
 
bool Initialize () override
 Called immediately after creation. Let provider initialize. More...
 
void Terminate () override
 Called just prior to deletion to allow releasing any resources. More...
 
EffectFamilySymbol GetOptionalFamilySymbol () override
 A symbol identifying the family of plug-ins provided by this. More...
 
const FileExtensionsGetFileExtensions () override
 File types associated with this protocol. More...
 
FilePath InstallPath () override
 Where plug-in files should be copied to install them. More...
 
void AutoRegisterPlugins (PluginManagerInterface &pm) override
 Called so that a provider of a static set of plug-ins can register them. More...
 
PluginPaths FindModulePaths (PluginManagerInterface &pm) override
 
unsigned DiscoverPluginsAtPath (const PluginPath &path, TranslatableString &errMsg, const RegistrationCallback &callback) override
 
bool CheckPluginExist (const PluginPath &path) const override
 Performs plugin/module existence check, still plugin may fail to load. Implementation should avoid loading plugins during this check. More...
 
std::unique_ptr< ComponentInterfaceLoadPlugin (const PluginPath &path) override
 Load the plug-in at a path reported by DiscoverPluginsAtPath. More...
 
- Public Member Functions inherited from PluginProvider
virtual ~PluginProvider ()
 
virtual bool Initialize ()=0
 Called immediately after creation. Let provider initialize. More...
 
virtual void Terminate ()=0
 Called just prior to deletion to allow releasing any resources. More...
 
virtual EffectFamilySymbol GetOptionalFamilySymbol ()=0
 A symbol identifying the family of plug-ins provided by this. More...
 
virtual const FileExtensionsGetFileExtensions ()=0
 File types associated with this protocol. More...
 
virtual FilePath InstallPath ()=0
 Where plug-in files should be copied to install them. More...
 
virtual void AutoRegisterPlugins (PluginManagerInterface &pluginManager)=0
 Called so that a provider of a static set of plug-ins can register them. More...
 
virtual bool SupportsCustomModulePaths () const
 
virtual PluginPaths FindModulePaths (PluginManagerInterface &pluginManager)=0
 
virtual unsigned DiscoverPluginsAtPath (const PluginPath &path, TranslatableString &errMsg, const RegistrationCallback &callback)=0
 
virtual bool CheckPluginExist (const PluginPath &path) const =0
 Performs plugin/module existence check, still plugin may fail to load. Implementation should avoid loading plugins during this check. More...
 
virtual std::unique_ptr< ValidatorMakeValidator () const
 
virtual std::unique_ptr< ComponentInterfaceLoadPlugin (const PluginPath &path)=0
 Load the plug-in at a path reported by DiscoverPluginsAtPath. More...
 
- Public Member Functions inherited from ComponentInterface
virtual ~ComponentInterface ()
 
virtual PluginPath GetPath () const =0
 
virtual ComponentInterfaceSymbol GetSymbol () const =0
 
virtual VendorSymbol GetVendor () const =0
 
virtual wxString GetVersion () const =0
 
virtual TranslatableString GetDescription () const =0
 
TranslatableString GetName () const
 

Private Types

using CommandHash = std::unordered_map< wxString, const Entry * >
 

Private Member Functions

std::unique_ptr< AudacityCommandInstantiate (const PluginPath &path)
 

Static Private Member Functions

static void DoRegistration (const ComponentInterfaceSymbol &name, const Factory &factory)
 

Private Attributes

CommandHash mCommands
 

Detailed Description

Internal module to auto register all built in commands. It is closely modelled on BuiltinEffectsModule.

Definition at line 30 of file LoadCommands.h.

Member Typedef Documentation

◆ CommandHash

using BuiltinCommandsModule::CommandHash = std::unordered_map< wxString, const Entry* >
private

Definition at line 86 of file LoadCommands.h.

◆ Factory

using BuiltinCommandsModule::Factory = std::function< std::unique_ptr<AudacityCommand> () >

Definition at line 36 of file LoadCommands.h.

Constructor & Destructor Documentation

◆ BuiltinCommandsModule()

BuiltinCommandsModule::BuiltinCommandsModule ( )

Definition at line 74 of file LoadCommands.cpp.

75{
76}

◆ ~BuiltinCommandsModule()

BuiltinCommandsModule::~BuiltinCommandsModule ( )
virtual

Definition at line 78 of file LoadCommands.cpp.

79{
80}

Member Function Documentation

◆ AutoRegisterPlugins()

void BuiltinCommandsModule::AutoRegisterPlugins ( PluginManagerInterface pluginManager)
overridevirtual

Called so that a provider of a static set of plug-ins can register them.

Implements PluginProvider.

Definition at line 145 of file LoadCommands.cpp.

146{
147 TranslatableString ignoredErrMsg;
148 for (const auto &pair : mCommands)
149 {
150 const auto &path = pair.first;
151 if (!pm.IsPluginRegistered(path, &pair.second->name.Msgid()))
152 {
153 // No checking of error ?
154 // Uses Generic Registration, not Default.
155 // Registers as TypeGeneric, not TypeEffect.
156 DiscoverPluginsAtPath(path, ignoredErrMsg,
158 }
159 }
160}
CommandHash mCommands
Definition: LoadCommands.h:87
unsigned DiscoverPluginsAtPath(const PluginPath &path, TranslatableString &errMsg, const RegistrationCallback &callback) override
static const PluginID & AudacityCommandRegistrationCallback(PluginProvider *provider, ComponentInterface *ident)
Holds a msgid for the translation catalog; may also bind format arguments.

References PluginManagerInterface::AudacityCommandRegistrationCallback(), DiscoverPluginsAtPath(), PluginManagerInterface::IsPluginRegistered(), and mCommands.

Here is the call graph for this function:

◆ CheckPluginExist()

bool BuiltinCommandsModule::CheckPluginExist ( const PluginPath path) const
overridevirtual

Performs plugin/module existence check, still plugin may fail to load. Implementation should avoid loading plugins during this check.

Parameters
pathInternal plugin path/ID discovered via DiscoverPluginsAtPath or module path returned by FindModulePaths

Implements PluginProvider.

Definition at line 197 of file LoadCommands.cpp.

198{
199 return mCommands.find( path ) != mCommands.end();
200}

References mCommands.

◆ DiscoverPluginsAtPath()

unsigned BuiltinCommandsModule::DiscoverPluginsAtPath ( const PluginPath path,
TranslatableString errMsg,
const RegistrationCallback callback 
)
overridevirtual

Implements PluginProvider.

Definition at line 171 of file LoadCommands.cpp.

174{
175 // At most one
176 errMsg = {};
177 auto Command = Instantiate(path);
178 if (Command)
179 {
180 if (callback){
181 callback(this, Command.get());
182 }
183 return 1;
184 }
185
186 errMsg = XO("Unknown built-in command name");
187 return 0;
188}
XO("Cut/Copy/Paste")
std::unique_ptr< AudacityCommand > Instantiate(const PluginPath &path)
constexpr auto Command
Definition: MenuRegistry.h:456

References MenuRegistry::Command, Instantiate(), and XO().

Referenced by AutoRegisterPlugins().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoRegistration()

void BuiltinCommandsModule::DoRegistration ( const ComponentInterfaceSymbol name,
const Factory factory 
)
staticprivate

Definition at line 40 of file LoadCommands.cpp.

42{
43 wxASSERT( !sInitialized );
44 Entry::Registry().emplace_back( Entry{ name, factory } );
45}
static RegisteredToolbarFactory factory
static bool sInitialized
Definition: LoadEffects.cpp:23
wxString name
Definition: TagsEditor.cpp:166
static Entries & Registry()

References factory, name, BuiltinCommandsModule::Entry::Registry(), and sInitialized.

Here is the call graph for this function:

◆ FindModulePaths()

PluginPaths BuiltinCommandsModule::FindModulePaths ( PluginManagerInterface pluginManager)
overridevirtual

Find available "paths", which may each be presented to the user, and then reexamined (possibly loading libraries) to find one or more plug-ins

Paths are not necessarily file system paths. Only the provider reinterprets the paths.

Modules may be associated with plug-ins, one-to-many.

See also
GetFileExtensions DiscoverPluginsAtPath

Implements PluginProvider.

Definition at line 162 of file LoadCommands.cpp.

163{
164 // Not really libraries
166 for ( const auto &pair : mCommands )
167 names.push_back( pair.first );
168 return names;
169}
std::vector< PluginPath > PluginPaths
Definition: Identifier.h:215
static TranslatableStrings names
Definition: TagsEditor.cpp:153

References mCommands, and names.

◆ GetDescription()

TranslatableString BuiltinCommandsModule::GetDescription ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 107 of file LoadCommands.cpp.

108{
109 return XO("Provides builtin commands to Audacity");
110}

References XO().

Here is the call graph for this function:

◆ GetFileExtensions()

const FileExtensions & BuiltinCommandsModule::GetFileExtensions ( )
overridevirtual

File types associated with this protocol.

"Paths" returned by FindModulePaths() and passed back to DiscoverPluginsAtPath() have provider-specific meaning. They are not necessarily file system paths to existent files that could be placed in any folder and queried for plug-in information.

This function returns nonempty only when that is the case, and lists the possible extensions of such files (an empty string in a nonempty array means any file is a candidate).

Implements PluginProvider.

Definition at line 139 of file LoadCommands.cpp.

140{
141 static FileExtensions empty;
142 return empty;
143}
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.

◆ GetOptionalFamilySymbol()

EffectFamilySymbol BuiltinCommandsModule::GetOptionalFamilySymbol ( )
overridevirtual

A symbol identifying the family of plug-ins provided by this.

If it is not empty, then the family as a whole can be enabled or disabled by the user in Preferences

Implements PluginProvider.

Definition at line 133 of file LoadCommands.cpp.

134{
135 // Commands are not enabled and disabled in EffectsPrefs
136 return {};
137}

◆ GetPath()

PluginPath BuiltinCommandsModule::GetPath ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 86 of file LoadCommands.cpp.

87{
88 return {};
89}

◆ GetSymbol()

ComponentInterfaceSymbol BuiltinCommandsModule::GetSymbol ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 91 of file LoadCommands.cpp.

92{
93 return XO("Builtin Commands");
94}

References XO().

Here is the call graph for this function:

◆ GetVendor()

VendorSymbol BuiltinCommandsModule::GetVendor ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 96 of file LoadCommands.cpp.

97{
98 return XO("The Audacity Team");
99}

References XO().

Here is the call graph for this function:

◆ GetVersion()

wxString BuiltinCommandsModule::GetVersion ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 101 of file LoadCommands.cpp.

102{
103 // This "may" be different if this were to be maintained as a separate DLL
104 return AUDACITY_VERSION_STRING;
105}

◆ Initialize()

bool BuiltinCommandsModule::Initialize ( )
overridevirtual

Called immediately after creation. Let provider initialize.

Returns
"true" if initialization was successful

Implements PluginProvider.

Definition at line 116 of file LoadCommands.cpp.

117{
118 for ( const auto &entry : Entry::Registry() ) {
119 auto path = wxString(BUILTIN_GENERIC_COMMAND_PREFIX)
120 + entry.name.Internal();
121 mCommands[ path ] = &entry;
122 }
123 sInitialized = true;
124 return true;
125}
#define BUILTIN_GENERIC_COMMAND_PREFIX
static ProjectFileIORegistry::AttributeWriterEntry entry

References BUILTIN_GENERIC_COMMAND_PREFIX, entry, mCommands, BuiltinCommandsModule::Entry::Registry(), and sInitialized.

Here is the call graph for this function:

◆ InstallPath()

FilePath BuiltinCommandsModule::InstallPath ( )
inlineoverridevirtual

Where plug-in files should be copied to install them.

Returns
may be empty. Drag-and-drop is supported only if GetFileExtensions() returns nonempty and this function returns nonempty.

Implements PluginProvider.

Definition at line 61 of file LoadCommands.h.

61{ return {}; }

◆ Instantiate()

std::unique_ptr< AudacityCommand > BuiltinCommandsModule::Instantiate ( const PluginPath path)
private

Definition at line 206 of file LoadCommands.cpp.

207{
208 wxASSERT(path.StartsWith(BUILTIN_GENERIC_COMMAND_PREFIX));
209 auto iter = mCommands.find( path );
210 if ( iter != mCommands.end() )
211 return iter->second->factory();
212
213 wxASSERT( false );
214 return nullptr;
215}

References BUILTIN_GENERIC_COMMAND_PREFIX, and mCommands.

Referenced by DiscoverPluginsAtPath(), and LoadPlugin().

Here is the caller graph for this function:

◆ LoadPlugin()

std::unique_ptr< ComponentInterface > BuiltinCommandsModule::LoadPlugin ( const PluginPath path)
overridevirtual

Load the plug-in at a path reported by DiscoverPluginsAtPath.

Returns
smart pointer managing the later unloading

Implements PluginProvider.

Definition at line 191 of file LoadCommands.cpp.

192{
193 // Acquires a resource for the application.
194 return Instantiate(path);
195}

References Instantiate().

Here is the call graph for this function:

◆ Terminate()

void BuiltinCommandsModule::Terminate ( )
overridevirtual

Called just prior to deletion to allow releasing any resources.

Implements PluginProvider.

Definition at line 127 of file LoadCommands.cpp.

128{
129 // Nothing to do here
130 return;
131}

Member Data Documentation

◆ mCommands

CommandHash BuiltinCommandsModule::mCommands
private

The documentation for this class was generated from the following files: