Audacity 3.2.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
PluginStartupRegistration Class Referencefinal

#include <PluginStartupRegistration.h>

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

Public Member Functions

 PluginStartupRegistration (const std::map< wxString, std::vector< wxString > > &pluginsToProcess)
 
void Run (std::chrono::seconds timeout=std::chrono::seconds(30))
 
const std::vector< wxString > & GetFailedPluginsPaths () const noexcept
 Returns list of paths of plugins that didn't pass validation for some reason. More...
 
void OnInternalError (const wxString &error) override
 Called on error, further processing is not possible. More...
 
void OnPluginFound (const PluginDescriptor &desc) override
 Called for each plugin instance found inside module. More...
 
void OnPluginValidationFailed (const wxString &providerId, const wxString &path) override
 
void OnValidationFinished () override
 Called when module processing finished. More...
 
- Public Member Functions inherited from AsyncPluginValidator::Delegate
virtual ~Delegate ()
 
virtual void OnPluginFound (const PluginDescriptor &plugin)=0
 Called for each plugin instance found inside module. More...
 
virtual void OnPluginValidationFailed (const wxString &providerId, const wxString &path)=0
 
virtual void OnValidationFinished ()=0
 Called when module processing finished. More...
 
virtual void OnInternalError (const wxString &msg)=0
 Called on error, further processing is not possible. More...
 

Private Member Functions

void Stop ()
 
void Skip ()
 
void StopWithError (const wxString &msg)
 
void ProcessNext ()
 

Private Attributes

std::unique_ptr< AsyncPluginValidatormValidator
 
std::vector< std::pair< wxString, std::vector< wxString > > > mPluginsToProcess
 
size_t mCurrentPluginIndex {0}
 
size_t mCurrentPluginProviderIndex {0}
 
bool mValidProviderFound {false}
 
std::vector< wxString > mFailedPluginsPaths
 
std::vector< PluginDescriptormFailedPluginsCache
 
wxWeakRef< wxDialogWrappermScanDialog
 
wxWeakRef< wxTimer > mTimeoutTimer
 
std::chrono::system_clock::duration mTimeout {}
 
std::chrono::system_clock::time_point mRequestStartTime {}
 

Detailed Description

Helper class that passes plugins provided in constructor to plugin validator, then "good" plugins are registered in PluginManager.

Definition at line 25 of file PluginStartupRegistration.h.

Constructor & Destructor Documentation

◆ PluginStartupRegistration()

PluginStartupRegistration::PluginStartupRegistration ( const std::map< wxString, std::vector< wxString > > &  pluginsToProcess)

Definition at line 130 of file PluginStartupRegistration.cpp.

131{
132 for(auto& p : pluginsToProcess)
133 mPluginsToProcess.push_back(p);
134}
std::vector< std::pair< wxString, std::vector< wxString > > > mPluginsToProcess

References mPluginsToProcess.

Member Function Documentation

◆ GetFailedPluginsPaths()

const std::vector< wxString > & PluginStartupRegistration::GetFailedPluginsPaths ( ) const
noexcept

Returns list of paths of plugins that didn't pass validation for some reason.

Definition at line 205 of file PluginStartupRegistration.cpp.

206{
207 return mFailedPluginsPaths;
208}
std::vector< wxString > mFailedPluginsPaths

References mFailedPluginsPaths.

◆ OnInternalError()

void PluginStartupRegistration::OnInternalError ( const wxString &  msg)
overridevirtual

Called on error, further processing is not possible.

Implements AsyncPluginValidator::Delegate.

Definition at line 136 of file PluginStartupRegistration.cpp.

137{
138 StopWithError(error);
139}
void StopWithError(const wxString &msg)

References StopWithError().

Here is the call graph for this function:

◆ OnPluginFound()

void PluginStartupRegistration::OnPluginFound ( const PluginDescriptor plugin)
overridevirtual

Called for each plugin instance found inside module.

Implements AsyncPluginValidator::Delegate.

Definition at line 141 of file PluginStartupRegistration.cpp.

142{
144 mFailedPluginsCache.clear();
145
146 mValidProviderFound = true;
147 if(!desc.IsValid())
148 mFailedPluginsCache.push_back(desc);
150}
const TranslatableString desc
Definition: ExportPCM.cpp:55
void RegisterPlugin(PluginDescriptor &&desc)
static PluginManager & Get()
std::vector< PluginDescriptor > mFailedPluginsCache

References desc, PluginManager::Get(), mFailedPluginsCache, mValidProviderFound, and PluginManager::RegisterPlugin().

Here is the call graph for this function:

◆ OnPluginValidationFailed()

void PluginStartupRegistration::OnPluginValidationFailed ( const wxString &  providerId,
const wxString &  path 
)
overridevirtual

Implements AsyncPluginValidator::Delegate.

Definition at line 152 of file PluginStartupRegistration.cpp.

153{
154 PluginID ID = providerId + wxT("_") + path;
155 PluginDescriptor pluginDescriptor;
156 pluginDescriptor.SetPluginType(PluginTypeStub);
157 pluginDescriptor.SetID(ID);
158 pluginDescriptor.SetProviderID(providerId);
159 pluginDescriptor.SetPath(path);
160 pluginDescriptor.SetEnabled(false);
161 pluginDescriptor.SetValid(false);
162
163 //Multiple providers can report same module paths
164 //do not register until all associated providers have tried to load the module
165 mFailedPluginsCache.push_back(std::move(pluginDescriptor));
166}
wxT("CloseDown"))
wxString PluginID
Definition: EffectManager.h:30
@ PluginTypeStub
void SetEnabled(bool enable)
void SetPath(const PluginPath &path)
void SetValid(bool valid)
void SetProviderID(const PluginID &providerID)
void SetID(const PluginID &ID)
void SetPluginType(PluginType type)

References mFailedPluginsCache, PluginTypeStub, PluginDescriptor::SetEnabled(), PluginDescriptor::SetID(), PluginDescriptor::SetPath(), PluginDescriptor::SetPluginType(), PluginDescriptor::SetProviderID(), PluginDescriptor::SetValid(), and wxT().

Referenced by Skip().

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

◆ OnValidationFinished()

void PluginStartupRegistration::OnValidationFinished ( )
overridevirtual

Called when module processing finished.

Implements AsyncPluginValidator::Delegate.

Definition at line 169 of file PluginStartupRegistration.cpp.

170{
174 {
175 if(!mFailedPluginsCache.empty())
176 {
177 //we've tried all providers associated with same module path...
179 {
180 //...but none of them succeeded
181 mFailedPluginsPaths.push_back(mFailedPluginsCache[0].GetPath());
182
183 //Same plugin path, but different providers, we need to register all of them
184 for(auto& desc : mFailedPluginsCache)
186 }
187 //plugin type was detected, but plugin instance validation has failed
188 else
189 {
190 for(auto& desc : mFailedPluginsCache)
191 {
192 if(desc.GetPluginType() != PluginTypeStub)
193 mFailedPluginsPaths.push_back(desc.GetPath());
194 }
195 }
196 }
199 mValidProviderFound = false;
200 mFailedPluginsCache.clear();
201 }
202 ProcessNext();
203}

References desc, PluginManager::Get(), mCurrentPluginIndex, mCurrentPluginProviderIndex, mFailedPluginsCache, mFailedPluginsPaths, mPluginsToProcess, mValidProviderFound, PluginTypeStub, ProcessNext(), and PluginManager::RegisterPlugin().

Referenced by Skip().

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

◆ ProcessNext()

void PluginStartupRegistration::ProcessNext ( )
private

Definition at line 288 of file PluginStartupRegistration.cpp.

289{
291 {
292 Stop();
293 return;
294 }
295
296 try
297 {
298 if(auto dialog = static_cast<PluginScanDialog*>(mScanDialog.get()))
299 {
300 const auto progress = static_cast<float>(mCurrentPluginIndex) / static_cast<float>(mPluginsToProcess.size());
301 dialog->UpdateProgress(
303 progress);
304 }
305 if(!mValidator)
306 mValidator = std::make_unique<AsyncPluginValidator>(*this);
307
308 mValidator->Validate(
311 );
312 mRequestStartTime = std::chrono::system_clock::now();
313 if(auto timer = mTimeoutTimer.get())
314 timer->StartOnce(std::chrono::duration_cast<std::chrono::milliseconds>(mTimeout).count());
315 }
316 catch(std::exception& e)
317 {
318 StopWithError(e.what());
319 }
320 catch(...)
321 {
322 StopWithError("unknown error");
323 }
324}
std::unique_ptr< AsyncPluginValidator > mValidator
wxWeakRef< wxDialogWrapper > mScanDialog
std::chrono::system_clock::time_point mRequestStartTime
std::chrono::system_clock::duration mTimeout

References mCurrentPluginIndex, mCurrentPluginProviderIndex, mPluginsToProcess, mRequestStartTime, mScanDialog, mTimeout, mTimeoutTimer, mValidator, Stop(), and StopWithError().

Referenced by OnValidationFinished(), and Run().

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

◆ Run()

void PluginStartupRegistration::Run ( std::chrono::seconds  timeout = std::chrono::seconds(30))

Starts validation, showing dialog that blocks execution until process is complete or canceled

Parameters
timeoutTime allowed to spend on a single plugin validation. Pass 0 to disable timeout.

Definition at line 210 of file PluginStartupRegistration.cpp.

211{
212 PluginScanDialog dialog(nullptr, wxID_ANY, XO("Searching for plugins"));
213 wxTimer timeoutTimer(&dialog, OnPluginScanTimeout);
214 mScanDialog = &dialog;
215 mTimeoutTimer = &timeoutTimer;
216 mTimeout = timeout;
217
218 dialog.Bind(wxEVT_BUTTON, [this](wxCommandEvent& evt) {
219 evt.Skip();
220 if(evt.GetId() == wxID_IGNORE)
221 Skip();
222 });
223 dialog.Bind(wxEVT_TIMER, [this](wxTimerEvent& evt) {
224 if(evt.GetId() == OnPluginScanTimeout)
225 {
226 if(mValidator && mValidator->InactiveSince() < mRequestStartTime)
227 Skip();
228 //else
229 // wxMessageBox("Please check for plugin popups!");
230 }
231 else
232 evt.Skip();
233 });
234 dialog.Bind(wxEVT_CLOSE_WINDOW, [this](wxCloseEvent& evt) {
235 evt.Skip();
236 mValidator.reset();
238 });
239
240 dialog.CenterOnScreen();
241 ProcessNext();
242 dialog.ShowModal();
243}
XO("Cut/Copy/Paste")
void Save()
Save to preferences.

References PluginManager::Get(), mScanDialog, mTimeout, mTimeoutTimer, mValidator, anonymous_namespace{PluginStartupRegistration.cpp}::OnPluginScanTimeout, ProcessNext(), PluginManager::Save(), Skip(), and XO().

Here is the call graph for this function:

◆ Skip()

void PluginStartupRegistration::Skip ( )
private

Definition at line 251 of file PluginStartupRegistration.cpp.

252{
253 //Drop current validator, no more callbacks will be received from now
254 mValidator->SetDelegate(nullptr);
255 //While on Linux and MacOS socket `shutdown()` wakes up `select()` almost
256 //immediately, on Windows it sometimes get delayed on unspecified amount
257 //of time. As we do not expect any data we can safely move remaining
258 //operations to another thread.
259 std::thread([validator = std::shared_ptr<AsyncPluginValidator>(std::move(mValidator))]{ }).detach();
260
262 {
263 // Validator didn't report anything yet or it tried
264 // one or more providers that didn't recognize the plugin.
265 // In that case we assume that none of the remaining providers
266 // can recognize that plugin.
267 // Note: create stub `PluginDescriptors` for each associated provider
273 }
274 //else
275 // Don't assume that `OnValidationFinished()` and `OnPluginFound()`
276 // aren't deferred within run loop
277
279}
void OnValidationFinished() override
Called when module processing finished.
void OnPluginValidationFailed(const wxString &providerId, const wxString &path) override

References mCurrentPluginIndex, mCurrentPluginProviderIndex, mPluginsToProcess, mValidator, mValidProviderFound, OnPluginValidationFailed(), and OnValidationFinished().

Referenced by Run().

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

◆ Stop()

void PluginStartupRegistration::Stop ( )
private

Definition at line 245 of file PluginStartupRegistration.cpp.

246{
247 if(auto dialog = mScanDialog.get())
248 dialog->Close();
249}

References mScanDialog.

Referenced by ProcessNext(), and StopWithError().

Here is the caller graph for this function:

◆ StopWithError()

void PluginStartupRegistration::StopWithError ( const wxString &  msg)
private

Definition at line 281 of file PluginStartupRegistration.cpp.

282{
283 //TODO: show error dialog?
284 wxLogError("Plugin registration error: %s", msg);
285 Stop();
286}

References Stop().

Referenced by OnInternalError(), and ProcessNext().

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

Member Data Documentation

◆ mCurrentPluginIndex

size_t PluginStartupRegistration::mCurrentPluginIndex {0}
private

Definition at line 30 of file PluginStartupRegistration.h.

Referenced by OnValidationFinished(), ProcessNext(), and Skip().

◆ mCurrentPluginProviderIndex

size_t PluginStartupRegistration::mCurrentPluginProviderIndex {0}
private

Definition at line 31 of file PluginStartupRegistration.h.

Referenced by OnValidationFinished(), ProcessNext(), and Skip().

◆ mFailedPluginsCache

std::vector<PluginDescriptor> PluginStartupRegistration::mFailedPluginsCache
private

◆ mFailedPluginsPaths

std::vector<wxString> PluginStartupRegistration::mFailedPluginsPaths
private

Definition at line 33 of file PluginStartupRegistration.h.

Referenced by GetFailedPluginsPaths(), and OnValidationFinished().

◆ mPluginsToProcess

std::vector<std::pair<wxString, std::vector<wxString> > > PluginStartupRegistration::mPluginsToProcess
private

◆ mRequestStartTime

std::chrono::system_clock::time_point PluginStartupRegistration::mRequestStartTime {}
private

Definition at line 38 of file PluginStartupRegistration.h.

Referenced by ProcessNext().

◆ mScanDialog

wxWeakRef<wxDialogWrapper> PluginStartupRegistration::mScanDialog
private

Definition at line 35 of file PluginStartupRegistration.h.

Referenced by ProcessNext(), Run(), and Stop().

◆ mTimeout

std::chrono::system_clock::duration PluginStartupRegistration::mTimeout {}
private

Definition at line 37 of file PluginStartupRegistration.h.

Referenced by ProcessNext(), and Run().

◆ mTimeoutTimer

wxWeakRef<wxTimer> PluginStartupRegistration::mTimeoutTimer
private

Definition at line 36 of file PluginStartupRegistration.h.

Referenced by ProcessNext(), and Run().

◆ mValidator

std::unique_ptr<AsyncPluginValidator> PluginStartupRegistration::mValidator
private

Definition at line 28 of file PluginStartupRegistration.h.

Referenced by ProcessNext(), Run(), and Skip().

◆ mValidProviderFound

bool PluginStartupRegistration::mValidProviderFound {false}
private

Definition at line 32 of file PluginStartupRegistration.h.

Referenced by OnPluginFound(), OnValidationFinished(), and Skip().


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