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}
void RegisterPlugin(PluginDescriptor &&desc)
static PluginManager & Get()
std::vector< PluginDescriptor > mFailedPluginsCache
const TranslatableString desc
Definition: ExportPCM.cpp:51

References anonymous_namespace{ExportPCM.cpp}::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
@ 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 anonymous_namespace{ExportPCM.cpp}::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 289 of file PluginStartupRegistration.cpp.

290{
292 {
293 Stop();
294 return;
295 }
296
297 try
298 {
299 if(auto dialog = static_cast<PluginScanDialog*>(mScanDialog.get()))
300 {
301 const auto progress = static_cast<float>(mCurrentPluginIndex) / static_cast<float>(mPluginsToProcess.size());
302 dialog->UpdateProgress(
304 progress);
305 }
306 if(!mValidator)
307 mValidator = std::make_unique<AsyncPluginValidator>(*this);
308
309 mValidator->Validate(
312 );
313 mRequestStartTime = std::chrono::system_clock::now();
314 if(auto timer = mTimeoutTimer.get())
315 timer->StartOnce(std::chrono::duration_cast<std::chrono::milliseconds>(mTimeout).count());
316 }
317 catch(std::exception& e)
318 {
319 StopWithError(e.what());
320 }
321 catch(...)
322 {
323 StopWithError("unknown error");
324 }
325}
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();
239 });
240
241 dialog.CenterOnScreen();
242 ProcessNext();
243 dialog.ShowModal();
244}
XO("Cut/Copy/Paste")
void Save()
Save to preferences.
void NotifyPluginsChanged()

References PluginManager::Get(), mScanDialog, mTimeout, mTimeoutTimer, mValidator, PluginManager::NotifyPluginsChanged(), 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 252 of file PluginStartupRegistration.cpp.

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

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

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 282 of file PluginStartupRegistration.cpp.

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

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: