KiCad PCB EDA Suite
Loading...
Searching...
No Matches
PCM_TASK_MANAGER Class Reference

Helper class that handles package (un)installation. More...

#include <pcm_task_manager.h>

Public Types

enum class  STATUS { FAILED = -1 , INITIALIZED = 0 , SUCCESS = 1 }
 
typedef std::function< STATUS()> PCM_TASK
 

Public Member Functions

 PCM_TASK_MANAGER (std::shared_ptr< PLUGIN_CONTENT_MANAGER > pcm)
 
PCM_TASK_MANAGER::STATUS DownloadAndInstall (const PCM_PACKAGE &aPackage, const wxString &aVersion, const wxString &aRepositoryId, const bool isUpdate)
 Enqueue package download and installation.
 
PCM_TASK_MANAGER::STATUS Uninstall (const PCM_PACKAGE &aPackage)
 Enqueue package uninstallation.
 
void RunQueue (wxWindow *aParent)
 Run queue of pending actions.
 
PCM_TASK_MANAGER::STATUS InstallFromFile (wxWindow *aParent, const wxString &aFilePath)
 Installs package from an archive file on disk.
 
std::unordered_set< PCM_PACKAGE_TYPE > & GetChangedPackageTypes ()
 

Private Member Functions

int downloadFile (const wxString &aFilePath, const wxString &aUrl)
 Download URL to a file.
 
PCM_TASK_MANAGER::STATUS installDownloadedPackage (const PCM_PACKAGE &aPackage, const wxString &aVersion, const wxString &aRepositoryId, const wxFileName &aFilePath, const bool isUpdate)
 Installs downloaded package archive.
 
bool extract (const wxString &aFilePath, const wxString &aPackageId, bool isMultiThreaded)
 Extract package archive.
 
void deletePackageDirectories (const wxString &aPackageId, const std::forward_list< wxRegEx > &aKeep={})
 Delete all package files.
 

Private Attributes

std::unique_ptr< DIALOG_PCM_PROGRESSm_reporter
 
SYNC_QUEUE< PCM_TASKm_download_queue
 
SYNC_QUEUE< PCM_TASKm_install_queue
 
std::shared_ptr< PLUGIN_CONTENT_MANAGERm_pcm
 
std::mutex m_changed_package_types_guard
 
std::unordered_set< PCM_PACKAGE_TYPEm_changed_package_types
 

Detailed Description

Helper class that handles package (un)installation.

Package state changes are first enqueued using DownloadAndInstall/Uninstall methods and then applied using RunQueue().

RunQueue() is multithreaded for better experience.

Definition at line 47 of file pcm_task_manager.h.

Member Typedef Documentation

◆ PCM_TASK

typedef std::function<STATUS()> PCM_TASK_MANAGER::PCM_TASK

Definition at line 57 of file pcm_task_manager.h.

Member Enumeration Documentation

◆ STATUS

enum class PCM_TASK_MANAGER::STATUS
strong
Enumerator
FAILED 
INITIALIZED 
SUCCESS 

Definition at line 50 of file pcm_task_manager.h.

Constructor & Destructor Documentation

◆ PCM_TASK_MANAGER()

PCM_TASK_MANAGER::PCM_TASK_MANAGER ( std::shared_ptr< PLUGIN_CONTENT_MANAGER pcm)
inline

Definition at line 59 of file pcm_task_manager.h.

Member Function Documentation

◆ deletePackageDirectories()

void PCM_TASK_MANAGER::deletePackageDirectories ( const wxString &  aPackageId,
const std::forward_list< wxRegEx > &  aKeep = {} 
)
private

Delete all package files.

Parameters
aPackageIdid of the package
aKeeplist of regex indicating which files should not be deleted

Definition at line 475 of file pcm_task_manager.cpp.

References _, m_pcm, m_reporter, PCM_PACKAGE_DIRECTORIES(), RPT_SEVERITY_ERROR, and RPT_SEVERITY_INFO.

Referenced by installDownloadedPackage(), and Uninstall().

◆ DownloadAndInstall()

PCM_TASK_MANAGER::STATUS PCM_TASK_MANAGER::DownloadAndInstall ( const PCM_PACKAGE aPackage,
const wxString &  aVersion,
const wxString &  aRepositoryId,
const bool  isUpdate 
)

Enqueue package download and installation.

Enqueues a download task for a given package version.

Download task fetches the package archive and if successful enqueues an installation task. Installation task verifies sha256 hash if specified, extracts the package, removes the downloaded archive and marks package as installed.

Both tasks report their state independently to a progress dialog.

Parameters
aPackagepackage metadata
aVersionversion to be installed
aRepositoryIdid of the source repository
Returns
int status of the process

Definition at line 57 of file pcm_task_manager.cpp.

References _, downloadFile(), FAILED, PATHS::GetUserCachePath(), PCM_PACKAGE::identifier, installDownloadedPackage(), m_download_queue, m_install_queue, m_reporter, SYNC_QUEUE< T >::push(), RPT_SEVERITY_ERROR, SUCCESS, and PCM_PACKAGE::versions.

Referenced by DIALOG_PCM::OnApplyChangesClicked().

◆ downloadFile()

int PCM_TASK_MANAGER::downloadFile ( const wxString &  aFilePath,
const wxString &  aUrl 
)
private

◆ extract()

bool PCM_TASK_MANAGER::extract ( const wxString &  aFilePath,
const wxString &  aPackageId,
bool  isMultiThreaded 
)
private

Extract package archive.

Parameters
aFilePathpath to the archive
aPackageIdid of the package
isMultiThreadedMUST be set to true if the caller is not running in the main thread
Returns
true if archive was extracted successfuly

Definition at line 236 of file pcm_task_manager.cpp.

References _, CopyStreamData(), m_pcm, m_reporter, PCM_PACKAGE_DIRECTORIES(), RPT_SEVERITY_ERROR, RPT_SEVERITY_INFO, and zip.

Referenced by installDownloadedPackage().

◆ GetChangedPackageTypes()

std::unordered_set< PCM_PACKAGE_TYPE > & PCM_TASK_MANAGER::GetChangedPackageTypes ( )
inline
Returns
types of packages that were installed/uninstalled by the task manager

Definition at line 122 of file pcm_task_manager.h.

References m_changed_package_types.

Referenced by DIALOG_PCM::OnApplyChangesClicked(), and DIALOG_PCM::OnInstallFromFileClicked().

◆ installDownloadedPackage()

PCM_TASK_MANAGER::STATUS PCM_TASK_MANAGER::installDownloadedPackage ( const PCM_PACKAGE aPackage,
const wxString &  aVersion,
const wxString &  aRepositoryId,
const wxFileName &  aFilePath,
const bool  isUpdate 
)
private

Installs downloaded package archive.

Parameters
aPackagepackage metadata
aVersionversion to be installed
aRepositoryIdid of the source repository
aFilePathpath to the archive
isUpdatetrue if this is an update operation
Returns
int status of the operation

Definition at line 155 of file pcm_task_manager.cpp.

References _, compile_keep_on_update_regex(), deletePackageDirectories(), extract(), FAILED, PCM_PACKAGE::identifier, m_changed_package_types, m_changed_package_types_guard, m_pcm, m_reporter, PCM_PACKAGE::name, RPT_SEVERITY_ERROR, RPT_SEVERITY_INFO, SUCCESS, PCM_PACKAGE::type, and PCM_PACKAGE::versions.

Referenced by DownloadAndInstall().

◆ InstallFromFile()

PCM_TASK_MANAGER::STATUS PCM_TASK_MANAGER::InstallFromFile ( wxWindow *  aParent,
const wxString &  aFilePath 
)

Installs package from an archive file on disk.

Unlike DownloadAndInstall/Uninstall methods this one immediately extracts the package and marks it as installed.

Parameters
aParentparent dialog for progress window
aFilePathpath to the archive file
Returns
int status of the process

Definition at line 322 of file pcm_task_manager.cpp.

References _, compile_keep_on_update_regex(), CopyStreamData(), FAILED, INITIALIZED, m_pcm, PLUGIN_CONTENT_MANAGER::PreparePackage(), RPT_SEVERITY_INFO, SUCCESS, and zip.

Referenced by DIALOG_PCM::OnInstallFromFileClicked().

◆ RunQueue()

void PCM_TASK_MANAGER::RunQueue ( wxWindow *  aParent)

Run queue of pending actions.

This method spawns 2 threads to concurrently run tasks in download and install queues until they are drained.

Download queue feeds into install queue so the install thread keeps running until download thread indicated that it's finished AND all installs are processed.

Parameters
aParentparent dialog for progress window

Definition at line 585 of file pcm_task_manager.cpp.

References _, SYNC_QUEUE< T >::empty(), INITIALIZED, m_download_queue, m_install_queue, m_reporter, SYNC_QUEUE< T >::pop(), RPT_SEVERITY_INFO, SYNC_QUEUE< T >::size(), and SUCCESS.

Referenced by DIALOG_PCM::OnApplyChangesClicked().

◆ Uninstall()

PCM_TASK_MANAGER::STATUS PCM_TASK_MANAGER::Uninstall ( const PCM_PACKAGE aPackage)

Enqueue package uninstallation.

Enqueues uninstallation task that removes all package files and marks package as uninstalled.

Parameters
aPackagepackage metadata
Returns
int status of the process

Definition at line 563 of file pcm_task_manager.cpp.

References _, deletePackageDirectories(), PCM_PACKAGE::identifier, m_changed_package_types, m_changed_package_types_guard, m_install_queue, m_pcm, m_reporter, PCM_PACKAGE::name, SYNC_QUEUE< T >::push(), RPT_SEVERITY_INFO, SUCCESS, and PCM_PACKAGE::type.

Referenced by DIALOG_PCM::OnApplyChangesClicked().

Member Data Documentation

◆ m_changed_package_types

std::unordered_set<PCM_PACKAGE_TYPE> PCM_TASK_MANAGER::m_changed_package_types
private

Definition at line 177 of file pcm_task_manager.h.

Referenced by GetChangedPackageTypes(), installDownloadedPackage(), and Uninstall().

◆ m_changed_package_types_guard

std::mutex PCM_TASK_MANAGER::m_changed_package_types_guard
private

Definition at line 176 of file pcm_task_manager.h.

Referenced by installDownloadedPackage(), and Uninstall().

◆ m_download_queue

SYNC_QUEUE<PCM_TASK> PCM_TASK_MANAGER::m_download_queue
private

Definition at line 173 of file pcm_task_manager.h.

Referenced by DownloadAndInstall(), and RunQueue().

◆ m_install_queue

SYNC_QUEUE<PCM_TASK> PCM_TASK_MANAGER::m_install_queue
private

Definition at line 174 of file pcm_task_manager.h.

Referenced by DownloadAndInstall(), RunQueue(), and Uninstall().

◆ m_pcm

std::shared_ptr<PLUGIN_CONTENT_MANAGER> PCM_TASK_MANAGER::m_pcm
private

◆ m_reporter

std::unique_ptr<DIALOG_PCM_PROGRESS> PCM_TASK_MANAGER::m_reporter
private

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