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 42 of file ModuleManager.h.

Constructor & Destructor Documentation

◆ Module()

Module::Module ( const FilePath name)

Definition at line 44 of file ModuleManager.cpp.

45 : mName{ name }
46{
47 mLib = std::make_unique<wxDynamicLibrary>();
48 mDispatch = NULL;
49}
wxString name
Definition: TagsEditor.cpp:166
fnModuleDispatch mDispatch
Definition: ModuleManager.h:59
std::unique_ptr< wxDynamicLibrary > mLib
Definition: ModuleManager.h:58
const FilePath mName
Definition: ModuleManager.h:57

References mDispatch, and mLib.

◆ ~Module()

Module::~Module ( )
virtual

Definition at line 51 of file ModuleManager.cpp.

52{
53 // DV: The current Registry code makes unloading of the modules
54 // impossible. The order in which static objects are destroyed
55 // may result in the Registry instance being destroyed after the ModuleManager.
56 // The way Audacity is currently implemented, it is not possible to
57 // guarantee that the ModuleManager instance is initialized before
58 // any of the Registry instances.
59 if (mLib != nullptr && mLib->IsLoaded())
60 mLib->Detach();
61}

References mLib.

Member Function Documentation

◆ Dispatch()

int Module::Dispatch ( ModuleDispatchTypes  type)

Definition at line 158 of file ModuleManager.cpp.

159{
160 if (mLib->IsLoaded())
161 if( mDispatch != NULL )
162 return mDispatch(type);
163
164 return 0;
165}

References mDispatch, and mLib.

◆ GetName()

const FilePath & Module::GetName ( ) const
inline

Definition at line 54 of file ModuleManager.h.

54{ return mName; }

References mName.

◆ GetSymbol()

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

Definition at line 167 of file ModuleManager.cpp.

168{
169 return mLib->GetSymbol(name);
170}

References mLib, and name.

◆ HasDispatch()

bool Module::HasDispatch ( )
inline

Definition at line 51 of file ModuleManager.h.

51{ return mDispatch != NULL; };

References mDispatch.

◆ Load()

bool Module::Load ( wxString &  deferredErrorMessage)

Definition at line 79 of file ModuleManager.cpp.

80{
81 deferredErrorMessage.clear();
82 // Will this ever happen???
83 if (mLib->IsLoaded()) {
84 if (mDispatch) {
85 return true;
86 }
87
88 // Any messages should have already been generated the first time it was loaded.
89 return false;
90 }
91
92 auto ShortName = wxFileName(mName).GetName();
93
94 if (!mLib->Load(mName, wxDL_NOW | wxDL_QUIET | wxDL_GLOBAL)) {
95 // For this failure path, only, there is a possibility of retrial
96 // after some other dependency of this module is loaded. So the
97 // error is not immediately reported.
98 deferredErrorMessage = wxString(wxSysErrorMsg());
99 return false;
100 }
101
102 // Check version string matches. (For now, they must match exactly)
103 tVersionFn versionFn = (tVersionFn)(mLib->GetSymbol(wxT(versionFnName)));
104 if (versionFn == NULL){
106 XO("The module \"%s\" does not provide a version string.\n\nIt will not be loaded.")
107 .Format( ShortName));
108 wxLogMessage(wxT("The module \"%s\" does not provide a version string. It will not be loaded."), mName);
109 mLib->Unload();
110 return false;
111 }
112
113 wxString moduleVersion = versionFn();
114 if( moduleVersion != AUDACITY_VERSION_STRING) {
116 XO("The module \"%s\" is matched with Audacity version \"%s\".\n\nIt will not be loaded.")
117 .Format(ShortName, moduleVersion));
118 wxLogMessage(wxT("The module \"%s\" is matched with Audacity version \"%s\". It will not be loaded."), mName, moduleVersion);
119 mLib->Unload();
120 return false;
121 }
122
124 if (!mDispatch) {
125 // Module does not provide a dispatch function.
126 return true;
127 }
128
129 // However if we do have it and it does not work,
130 // then the module is bad.
131 bool res = ((mDispatch(ModuleInitialize))!=0);
132 if (res) {
133 return true;
134 }
135
136 mDispatch = NULL;
137
139 XO("The module \"%s\" failed to initialize.\n\nIt will not be loaded.")
140 .Format(ShortName));
141 wxLogMessage(wxT("The module \"%s\" failed to initialize.\nIt will not be loaded."), mName);
142 mLib->Unload();
143
144 return false;
145}
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:40
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 70 of file ModuleManager.cpp.

71{
72 auto ShortName = wxFileName(mName).GetName();
74 XO("Unable to load the \"%s\" module.\n\nError: %s")
75 .Format(ShortName, Error));
76 wxLogMessage(wxT("Unable to load the module \"%s\". Error: %s"), mName, Error);
77}

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

Here is the call graph for this function:

◆ Unload()

void Module::Unload ( )

Definition at line 148 of file ModuleManager.cpp.

149{
150 if (mLib->IsLoaded()) {
151 if (mDispatch)
153 }
154
155 mLib->Unload();
156}
@ ModuleTerminate

References mDispatch, mLib, and ModuleTerminate.

Member Data Documentation

◆ mDispatch

fnModuleDispatch Module::mDispatch
private

Definition at line 59 of file ModuleManager.h.

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

◆ mLib

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

Definition at line 58 of file ModuleManager.h.

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

◆ mName

const FilePath Module::mName
private

Definition at line 57 of file ModuleManager.h.

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


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