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

#include <ModuleManager.h>

Public Member Functions

 Module (const wxString &name)
 
virtual ~Module ()
 
bool Load ()
 
void Unload ()
 
int Dispatch (ModuleDispatchTypes type)
 
void * GetSymbol (const wxString &name)
 

Private Attributes

wxString mName
 
std::unique_ptr< wxDynamicLibrary > mLib
 
fnModuleDispatch mDispatch
 

Detailed Description

Definition at line 48 of file ModuleManager.h.

Constructor & Destructor Documentation

Module::Module ( const wxString &  name)

Definition at line 88 of file ModuleManager.cpp.

References mDispatch, mLib, mName, and name.

89 {
90  mName = name;
91  mLib = std::make_unique<wxDynamicLibrary>();
92  mDispatch = NULL;
93 }
fnModuleDispatch mDispatch
Definition: ModuleManager.h:62
wxString mName
Definition: ModuleManager.h:60
const wxChar * name
Definition: Distortion.cpp:94
std::unique_ptr< wxDynamicLibrary > mLib
Definition: ModuleManager.h:61
Module::~Module ( )
virtual

Definition at line 95 of file ModuleManager.cpp.

96 {
97 }

Member Function Documentation

int Module::Dispatch ( ModuleDispatchTypes  type)

Definition at line 158 of file ModuleManager.cpp.

References mDispatch, and mLib.

159 {
160  if (mLib->IsLoaded())
161  if( mDispatch != NULL )
162  return mDispatch(type);
163 
164  return 0;
165 }
fnModuleDispatch mDispatch
Definition: ModuleManager.h:62
std::unique_ptr< wxDynamicLibrary > mLib
Definition: ModuleManager.h:61
void * Module::GetSymbol ( const wxString &  name)

Definition at line 167 of file ModuleManager.cpp.

References mLib.

168 {
169  return mLib->GetSymbol(name);
170 }
const wxChar * name
Definition: Distortion.cpp:94
std::unique_ptr< wxDynamicLibrary > mLib
Definition: ModuleManager.h:61
bool Module::Load ( )

Definition at line 99 of file ModuleManager.cpp.

References _(), AUDACITY_VERSION_STRING, AudacityMessageBox(), mDispatch, mLib, mName, ModuleDispatchName, ModuleInitialize, and versionFnName.

100 {
101  if (mLib->IsLoaded()) {
102  if (mDispatch) {
103  return true;
104  }
105  return false;
106  }
107 
108  if (!mLib->Load(mName, wxDL_LAZY)) {
109  return false;
110  }
111 
112  // Check version string matches. (For now, they must match exactly)
113  tVersionFn versionFn = (tVersionFn)(mLib->GetSymbol(wxT(versionFnName)));
114  if (versionFn == NULL){
115  wxString ShortName = wxFileName( mName ).GetName();
116  AudacityMessageBox(wxString::Format(_("The module %s does not provide a version string.\nIt will not be loaded."), ShortName), _("Module Unsuitable"));
117  wxLogMessage(wxString::Format(_("The module %s does not provide a version string. It will not be loaded."), mName));
118  mLib->Unload();
119  return false;
120  }
121 
122  wxString moduleVersion = versionFn();
123  if( !moduleVersion.IsSameAs(AUDACITY_VERSION_STRING)) {
124  wxString ShortName = wxFileName( mName ).GetName();
125  AudacityMessageBox(wxString::Format(_("The module %s is matched with Audacity version %s.\n\nIt will not be loaded."), ShortName, moduleVersion), _("Module Unsuitable"));
126  wxLogMessage(wxString::Format(_("The module %s is matched with Audacity version %s. It will not be loaded."), mName, moduleVersion));
127  mLib->Unload();
128  return false;
129  }
130 
131  mDispatch = (fnModuleDispatch) mLib->GetSymbol(wxT(ModuleDispatchName));
132  if (!mDispatch) {
133  // Module does not provide a dispatch function...
134  // That can be OK, as long as we never try to call it.
135  return true;
136  }
137 
138  // However if we do have it and it does not work,
139  // then the module is bad.
140  bool res = ((mDispatch(ModuleInitialize))!=0);
141  if (res) {
142  return true;
143  }
144 
145  mDispatch = NULL;
146  return false;
147 }
#define AUDACITY_VERSION_STRING
Definition: Audacity.h:81
int(* fnModuleDispatch)(ModuleDispatchTypes type)
Definition: ModuleManager.h:46
int AudacityMessageBox(const wxString &message, const wxString &caption=AudacityMessageBoxCaptionStr(), long style=wxOK|wxCENTRE, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
Definition: ErrorDialog.h:92
fnModuleDispatch mDispatch
Definition: ModuleManager.h:62
#define versionFnName
wxString mName
Definition: ModuleManager.h:60
wxChar *(* tVersionFn)()
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
#define ModuleDispatchName
Definition: ModuleManager.h:33
std::unique_ptr< wxDynamicLibrary > mLib
Definition: ModuleManager.h:61
void Module::Unload ( )

Definition at line 149 of file ModuleManager.cpp.

References mDispatch, mLib, and ModuleTerminate.

150 {
151  if (mLib->IsLoaded()) {
153  }
154 
155  mLib->Unload();
156 }
fnModuleDispatch mDispatch
Definition: ModuleManager.h:62
std::unique_ptr< wxDynamicLibrary > mLib
Definition: ModuleManager.h:61

Member Data Documentation

fnModuleDispatch Module::mDispatch
private

Definition at line 62 of file ModuleManager.h.

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

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

Definition at line 61 of file ModuleManager.h.

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

wxString Module::mName
private

Definition at line 60 of file ModuleManager.h.

Referenced by Load(), and Module().


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