Audacity 3.2.0
Public Member Functions | Private Attributes | List of all members
Module Class Reference

#include <ModuleManager.h>

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

Public Member Functions

 Module (const FilePath &name)
 
virtual ~Module ()
 
void ShowLoadFailureError (const wxString &Error)
 
bool Load (wxString &deferredErrorMessage)
 
void Unload ()
 
bool HasDispatch ()
 
int Dispatch (ModuleDispatchTypes type)
 
void * GetSymbol (const wxString &name)
 
const FilePathGetName () const
 

Private Attributes

const FilePath mName
 
std::unique_ptr< wxDynamicLibrary > mLib
 
fnModuleDispatch mDispatch
 

Detailed Description

Definition at line 41 of file ModuleManager.h.

Constructor & Destructor Documentation

◆ Module()

Module::Module ( const FilePath name)

Definition at line 46 of file ModuleManager.cpp.

47 : mName{ name }
48{
49 mLib = std::make_unique<wxDynamicLibrary>();
50 mDispatch = NULL;
51}
const TranslatableString name
Definition: Distortion.cpp:76
fnModuleDispatch mDispatch
Definition: ModuleManager.h:58
std::unique_ptr< wxDynamicLibrary > mLib
Definition: ModuleManager.h:57
const FilePath mName
Definition: ModuleManager.h:56

References mDispatch, and mLib.

◆ ~Module()

Module::~Module ( )
virtual

Definition at line 53 of file ModuleManager.cpp.

54{
55}

Member Function Documentation

◆ Dispatch()

int Module::Dispatch ( ModuleDispatchTypes  type)

Definition at line 152 of file ModuleManager.cpp.

153{
154 if (mLib->IsLoaded())
155 if( mDispatch != NULL )
156 return mDispatch(type);
157
158 return 0;
159}

References mDispatch, and mLib.

◆ GetName()

const FilePath & Module::GetName ( ) const
inline

Definition at line 53 of file ModuleManager.h.

53{ return mName; }

References mName.

◆ GetSymbol()

void * Module::GetSymbol ( const wxString &  name)

Definition at line 161 of file ModuleManager.cpp.

162{
163 return mLib->GetSymbol(name);
164}

References mLib, and name.

◆ HasDispatch()

bool Module::HasDispatch ( )
inline

Definition at line 50 of file ModuleManager.h.

50{ return mDispatch != NULL; };

References mDispatch.

◆ Load()

bool Module::Load ( wxString &  deferredErrorMessage)

Definition at line 73 of file ModuleManager.cpp.

74{
75 deferredErrorMessage.clear();
76 // Will this ever happen???
77 if (mLib->IsLoaded()) {
78 if (mDispatch) {
79 return true;
80 }
81
82 // Any messages should have already been generated the first time it was loaded.
83 return false;
84 }
85
86 auto ShortName = wxFileName(mName).GetName();
87
88 if (!mLib->Load(mName, wxDL_NOW | wxDL_QUIET | wxDL_GLOBAL)) {
89 // For this failure path, only, there is a possibility of retrial
90 // after some other dependency of this module is loaded. So the
91 // error is not immediately reported.
92 deferredErrorMessage = wxString(wxSysErrorMsg());
93 return false;
94 }
95
96 // Check version string matches. (For now, they must match exactly)
97 tVersionFn versionFn = (tVersionFn)(mLib->GetSymbol(wxT(versionFnName)));
98 if (versionFn == NULL){
100 XO("The module \"%s\" does not provide a version string.\n\nIt will not be loaded.")
101 .Format( ShortName));
102 wxLogMessage(wxT("The module \"%s\" does not provide a version string. It will not be loaded."), mName);
103 mLib->Unload();
104 return false;
105 }
106
107 wxString moduleVersion = versionFn();
108 if( moduleVersion != AUDACITY_VERSION_STRING) {
110 XO("The module \"%s\" is matched with Audacity version \"%s\".\n\nIt will not be loaded.")
111 .Format(ShortName, moduleVersion));
112 wxLogMessage(wxT("The module \"%s\" is matched with Audacity version \"%s\". It will not be loaded."), mName, moduleVersion);
113 mLib->Unload();
114 return false;
115 }
116
118 if (!mDispatch) {
119 // Module does not provide a dispatch function.
120 return true;
121 }
122
123 // However if we do have it and it does not work,
124 // then the module is bad.
125 bool res = ((mDispatch(ModuleInitialize))!=0);
126 if (res) {
127 return true;
128 }
129
130 mDispatch = NULL;
131
133 XO("The module \"%s\" failed to initialize.\n\nIt will not be loaded.")
134 .Format(ShortName));
135 wxLogMessage(wxT("The module \"%s\" failed to initialize.\nIt will not be loaded."), mName);
136 mLib->Unload();
137
138 return false;
139}
wxT("CloseDown"))
XO("Cut/Copy/Paste")
#define ModuleDispatchName
@ ModuleInitialize
static BasicUI::MessageBoxResult DoMessageBox(const TranslatableString &msg)
#define versionFnName
wxChar *(* tVersionFn)()
int(* fnModuleDispatch)(ModuleDispatchTypes type)
Definition: ModuleManager.h:39
Abstract base class used in importing a file.

References DoMessageBox(), mDispatch, mLib, mName, ModuleDispatchName, ModuleInitialize, versionFnName, wxT(), and XO().

Here is the call graph for this function:

◆ ShowLoadFailureError()

void Module::ShowLoadFailureError ( const wxString &  Error)

Definition at line 64 of file ModuleManager.cpp.

65{
66 auto ShortName = wxFileName(mName).GetName();
68 XO("Unable to load the \"%s\" module.\n\nError: %s")
69 .Format(ShortName, Error));
70 wxLogMessage(wxT("Unable to load the module \"%s\". Error: %s"), mName, Error);
71}

References DoMessageBox(), Error, mName, wxT(), and XO().

Here is the call graph for this function:

◆ Unload()

void Module::Unload ( )

Definition at line 142 of file ModuleManager.cpp.

143{
144 if (mLib->IsLoaded()) {
145 if (mDispatch)
147 }
148
149 mLib->Unload();
150}
@ ModuleTerminate

References mDispatch, mLib, and ModuleTerminate.

Member Data Documentation

◆ mDispatch

fnModuleDispatch Module::mDispatch
private

Definition at line 58 of file ModuleManager.h.

Referenced by Dispatch(), HasDispatch(), Load(), Module(), and Unload().

◆ mLib

std::unique_ptr<wxDynamicLibrary> Module::mLib
private

Definition at line 57 of file ModuleManager.h.

Referenced by Dispatch(), GetSymbol(), Load(), Module(), and Unload().

◆ mName

const FilePath Module::mName
private

Definition at line 56 of file ModuleManager.h.

Referenced by GetName(), Load(), and ShowLoadFailureError().


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