KiCad PCB EDA Suite
|
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_PROGRESS > | m_reporter |
SYNC_QUEUE< PCM_TASK > | m_download_queue |
SYNC_QUEUE< PCM_TASK > | m_install_queue |
std::shared_ptr< PLUGIN_CONTENT_MANAGER > | m_pcm |
std::mutex | m_changed_package_types_guard |
std::unordered_set< PCM_PACKAGE_TYPE > | m_changed_package_types |
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.
typedef std::function<STATUS()> PCM_TASK_MANAGER::PCM_TASK |
Definition at line 57 of file pcm_task_manager.h.
|
strong |
Enumerator | |
---|---|
FAILED | |
INITIALIZED | |
SUCCESS |
Definition at line 50 of file pcm_task_manager.h.
|
inline |
Definition at line 59 of file pcm_task_manager.h.
|
private |
Delete all package files.
aPackageId | id of the package |
aKeep | list 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().
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.
aPackage | package metadata |
aVersion | version to be installed |
aRepositoryId | id of the source repository |
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().
|
private |
Download URL to a file.
aFilePath | path to file |
aUrl | URL to download |
Definition at line 112 of file pcm_task_manager.cpp.
References _, KICAD_CURL_EASY::GetErrorText(), KICAD_CURL_EASY::GetTransferTotal(), m_reporter, KICAD_CURL_EASY::Perform(), RPT_SEVERITY_ERROR, RPT_SEVERITY_INFO, KICAD_CURL_EASY::SetFollowRedirects(), KICAD_CURL_EASY::SetOutputStream(), KICAD_CURL_EASY::SetTransferCallback(), and KICAD_CURL_EASY::SetURL().
Referenced by DownloadAndInstall().
|
private |
Extract package archive.
aFilePath | path to the archive |
aPackageId | id of the package |
isMultiThreaded | MUST be set to true if the caller is not running in the main thread |
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().
|
inline |
Definition at line 122 of file pcm_task_manager.h.
References m_changed_package_types.
Referenced by DIALOG_PCM::OnApplyChangesClicked(), and DIALOG_PCM::OnInstallFromFileClicked().
|
private |
Installs downloaded package archive.
aPackage | package metadata |
aVersion | version to be installed |
aRepositoryId | id of the source repository |
aFilePath | path to the archive |
isUpdate | true if this is an update 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().
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.
aParent | parent dialog for progress window |
aFilePath | path to the archive file |
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().
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.
aParent | parent 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().
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.
aPackage | package metadata |
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().
|
private |
Definition at line 177 of file pcm_task_manager.h.
Referenced by GetChangedPackageTypes(), installDownloadedPackage(), and Uninstall().
|
private |
Definition at line 176 of file pcm_task_manager.h.
Referenced by installDownloadedPackage(), and Uninstall().
|
private |
Definition at line 173 of file pcm_task_manager.h.
Referenced by DownloadAndInstall(), and RunQueue().
|
private |
Definition at line 174 of file pcm_task_manager.h.
Referenced by DownloadAndInstall(), RunQueue(), and Uninstall().
|
private |
Definition at line 175 of file pcm_task_manager.h.
Referenced by deletePackageDirectories(), extract(), installDownloadedPackage(), InstallFromFile(), and Uninstall().
|
private |
Definition at line 172 of file pcm_task_manager.h.
Referenced by deletePackageDirectories(), DownloadAndInstall(), downloadFile(), extract(), installDownloadedPackage(), RunQueue(), and Uninstall().